lvt*_*llo 41 credentials jenkins jenkins-pipeline
我在声明式jenkins管道中有以下步骤:我resources/
使用libraryResource 创建来自我的文件夹的脚本.此脚本包含我的autobuild
用户和某些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 "
}
}
}
Run Code Online (Sandbox Code Playgroud)
这很好用.我可以使用我的autobuild
用户.现在我正在寻找最好的方法,我也可以包括我的admintest
用户的crendentials .我是否必须用第二withCredentials
部分"嵌套"它还是可以再添加一个usernamePassword
"数组"?
Vit*_*nko 79
当然,您可以使用一个withCredentials
块将多个凭据分配给不同的变量.
withCredentials([
usernamePassword(credentialsId: credsId1, usernameVariable: 'USER1', passwordVariable: 'PASS1'),
usernamePassword(credentialsId: credsId2, usernameVariable: 'USER2', passwordVariable: 'PASS2')
]){
//...
}
Run Code Online (Sandbox Code Playgroud)
此外,您可以将其与 $class 一起使用
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'awsID',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'],
[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'myID',
usernameVariable: 'USR',
passwordVariable: 'PWD']])
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
21506 次 |
最近记录: |