在配置作业以运行管道时,我可以选择添加到凭据插件中的凭据。
我了解使用 GitSCM 插件检出代码的一般格式是
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanCheckout']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: '1234-5678-abcd', url: 'git@github.com:jenkinsci/jenkins.git']]
])
从 here 开始,假设存在 ID 为 1234-5678-abcd
的凭据。
问题是,如果我更改要在作业中使用的凭据,我希望该更改自动传播到我的管道。我期待有一个变量可以代替硬编码的凭据 ID,该 ID 将扩展为用于检出管道的凭据的 ID。使用 GIT_USERNAME
时类似于 withCredentials
变量:
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanCheckout']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: $SCMCredentialID, url: 'git@github.com:jenkinsci/jenkins.git']]
])
$SCMCredentialID
将扩展为作业中配置的任何凭据。
谢谢!!