[英]How to use multiple credentials in withCredentials in Jenkins Pipeline
I have the following step in my declarative jenkins pipeline: I create script which comes from my resources/
folder using libraryResource.我在声明性 jenkins 管道中有以下步骤:我使用 libraryResource 创建来自我的
resources/
文件夹的脚本。 This script contains credentials for my autobuild
user and for some admintest
user.此脚本包含我的
autobuild
admintest
用户和某些admintest
用户的凭据。
stage('Build1') {
steps {
node{
def script = libraryResource 'tests/test.sh'
writeFile file: 'script.sh', text: script
sh 'chmod +x script.sh'
withCredentials([usernamePassword(credentialsId: xxx, usernameVariable: 'AUTOBUILD_USER', passwordVariable: 'AUTOBUILD_PASSWD')]){
sh './script.sh "
}
}
}
This works fine.这工作正常。 I can use my
autobuild
user.我可以使用我的
autobuild
用户。 Now I'm searching for the best way how I can include also the crendentials of my admintest
user.现在,我正在寻找最佳方式,如何同时包含我的
admintest
用户的admintest
。 Do I have to 'nest' it with a second withCredentials
part or can I add again a usernamePassword
'array'?我是否必须使用第二个
withCredentials
部分“嵌套”它,还是可以再次添加usernamePassword
'array'?
Sure, you can use one withCredentials
block to assign multiple credentials to different variables.当然,您可以使用一个
withCredentials
块将多个凭据分配给不同的变量。
withCredentials([
usernamePassword(credentialsId: credsId1, usernameVariable: 'USER1', passwordVariable: 'PASS1'),
usernamePassword(credentialsId: credsId2, usernameVariable: 'USER2', passwordVariable: 'PASS2')
]){
//...
}
Also, you can use this with $class此外,您可以将其与 $class 一起使用
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'awsID',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'],
[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'myID',
usernameVariable: 'USR',
passwordVariable: 'PWD']])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.