【发布时间】:2020-01-11 06:32:42
【问题描述】:
我正在使用 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?
【问题讨论】: