简体   繁体   English

Jenkins(自由式项目)密文使用参数表达式

[英]Jenkins (freestyle project) secret text using Parameter expression

I have a python project that I'm using pytest with integration to Report Portal.我有一个 python 项目,我正在使用 pytest 与报告门户集成。
I execute the tests from Jenkins (freestyle project).我从 Jenkins(自由式项目)执行测试。

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.为了在 Report Portal 中获取每个 session 的用户名,我需要知道用户的 Report Portal access_token
After finding those, I added to Jenkins for each user a secret text with the ID as the user Jenkins BUILD_USER_ID .找到这些后,我为每个用户添加到 Jenkins 一个秘密文本,其 ID 为用户 Jenkins BUILD_USER_ID

Next, In the Jenkins configure page, I clicked on Use secret text(s) or file(s) under Build Environment接下来,在 Jenkins 配置页面中,我单击Build EnvironmentUse secret text(s) or file(s)
Then clicked on Add and Secret text .然后点击Add and Secret text
I called the Variable RP_UUID .我调用了变量RP_UUID
And set Credentials to Parameter expression .并将Credentials设置为Parameter expression

Jenkins gave me a hint: Jenkins 给了我一个提示:

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:我尝试将此字段设置为${ BUILD_USER_ID } ,但出现以下错误:

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.我尝试了各种各样的东西,但这个阶段的 Jenkins 似乎无法识别任何变量名。

Any idea how to resolve this, or any different approach?知道如何解决这个问题或任何不同的方法吗?

ps ps
The field Set Jenkins user build variables is ticked.字段Set Jenkins user build variables被勾选。

See JENKINS-36470 the only parameter type that can be expanded in the Parameter expression section is a Credentials Parameter.请参阅JENKINS-36470参数表达式部分中唯一可以扩展的参数类型是凭据参数。 All other parameters are not supported.不支持所有其他参数。 So if you want to use this mechanism you must define the input parameter as a Credentials type:因此,如果您想使用这种机制,您必须将输入参数定义为 Credentials 类型:

在此处输入图像描述

You'd probably need to set "Run as SYSTEM" in Access Control for Builds at您可能需要在 Access Control for Builds 中设置“Run as SYSTEM”

https://jenkins-url/configureSecurity https://jenkins-url/configureSecurity

在此处输入图像描述

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.一旦我在“每个项目可配置的构建授权”下也设置了它 - 然后触发的作业可以评估凭据绑定的参数表达式。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM