我在Jobdsl中使用詹金斯来创建詹金斯工作。我试图通过在活动选择参数中添加常规脚本来构建参数化作业。该脚本使用存储在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}' ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句