[英]How to use the credentials stored in Jenkins in a groovy script in jenkins DSL
我正在使用 jenkins 和 Jobdsl 来创建 jenkins 工作。 我正在尝试通过在活动选择参数中添加一个 groovy 脚本来构建参数化作业。 该脚本使用存储在 jenkins 凭据中的凭据,我正在尝试使用代码在我的脚本中获取它
import jenkins.model.*
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
credentialsId = '1672622gjj'
def jenkinsCredentials = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.Credentials.class,
Jenkins.instance,
null,
null
).find{it.id == credentialsId};
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class, Jenkins.instance, null, null ).find{
it.id == credentialsId}
println(creds.username)
println(creds.password)
This code gives me the credential name and password but the result of the branches is blank. I am using `creds.password` as the authorization token.
What I am doing wrong?
你可以用同样的方式替换那里的字符串,你已经用你的脚本名称( +
字符串)做了,但这一点都不常规。
所以这应该有效:
... "curl ... 'Authorization: token ${creds.password}' ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.