Jenkins (freestyle project) secret text using Parameter expression

2.9k Views Asked by At

I have a python project that I'm using pytest with integration to Report Portal.
I execute the tests from Jenkins (freestyle project).

In order to to get the user name for each session in Report Portal, I need to know the Report Portal access_token of the user.
After finding those, I added to Jenkins for each user a secret text with the ID as the user Jenkins BUILD_USER_ID.

Next, In the Jenkins configure page, I clicked on Use secret text(s) or file(s) under Build Environment
Then clicked on Add and Secret text.
I called the Variable RP_UUID.
And set Credentials to Parameter expression.

Jenkins gave me a hint:

A valid parameter expression consists of the parameter name enclosed within ${ and }

I tried to set this filed to be ${ BUILD_USER_ID }, but I got the following error:

Rebuilds build #17
Running as SYSTEM
Building remotely on Automation in workspace /var/lib/jenkins/workspace/test
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] Done
ERROR: Could not find credentials entry with ID '${ BUILD_USER_ID }'
Finished: FAILURE

I tried all sorts of things, but it seems that Jenkins in this stage doesn't recognize any variable name.

Any idea how to resolve this, or any different approach?

p.s.
The field Set Jenkins user build variables is ticked.

1

There are 1 best solutions below

0
On

You'd probably need to set "Run as SYSTEM" in Access Control for Builds at

https://jenkins-url/configureSecurity

enter image description here

When I used "Run as SYSTEM" just for "Project default Build Authorization" it didn't work. Once I set it also under "Per-project configurable Build Authorization" - Then the triggered job could evaluate the parameter expression for the credentials bindings.

enter image description here