简体   繁体   English

如何在 Jenkins Pipeline 的 withCredentials 中使用多个凭据

[英]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.

相关问题 如何在 jenkins 管道 groovy 文件中使用 withcredentials 设置多个凭据 - How to Set multiple credentials using withcredentials in jenkins pipeline groovy file 在 Jenkins 管道库中使用 withCredentials([usernamePassword(... ) ]) - Use withCredentials([usernamePassword( ... ) ]) in Jenkins Pipeline Library Jenkins 2.18 withCredentials 在管道中不起作用(凭据绑定插件) - Jenkins 2.18 withCredentials doesnt work in pipeline (Credentials Binding Plugin) 如何在 Jenkins 中使用 withCredentials for Perforce? - How to use withCredentials for Perforce in Jenkins? 在詹金斯的withcredentials中有条件地选择凭证 - Conditionally selecting credentials in withcredentials in jenkins 当我与withCredentials一起使用时,Jenkins声明性管道会抛出NullPointerException - Jenkins Declarative Pipeline throws NullPointerException when I use withCredentials 如何在不屏蔽 withCredentials.usernamePassword 中的 PASSWORD 的情况下重用 Jenkins 凭据? - How to reuse Jenkins credentials without masking the PASSWORD in withCredentials.usernamePassword? Jenkins:如何使用jenkins pipeline Multiple parameters - Jenkins: How to use jenkins pipeline Multiple parameters 如何使用来自 Jenkins 管道输入到 docker 文件的 git 凭据? - How to use git credentials from Jenkins pipeline input into docker file? 如何在 Jenkins 管道中使用多个 docker 存储库 - How to use multiple docker repositories in a Jenkins pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM