如何在Jenkins Pipeline中的withCredentials中使用多个凭据 [英] How to use multiple credentials in withCredentials in Jenkins Pipeline

查看:3984
本文介绍了如何在Jenkins Pipeline中的withCredentials中使用多个凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在声明性jenkins管道中执行以下步骤: 我使用libraryResource创建了来自resources/文件夹的脚本.该脚本包含我的autobuild用户和某些admintest用户的凭据.

I have the following step in my declarative jenkins pipeline: I create script which comes from my resources/ folder using libraryResource. This script contains credentials for my autobuild user and for some admintest user.

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 "
                        }

                    }

                }   

这很好.我可以使用我的autobuild用户.现在,我正在寻找最好的方式来包含admintest用户的凭据. 我是否必须用第二个withCredentials部分嵌套",还是可以再次添加usernamePassword数组"?

This works fine. I can use my autobuild user. Now I'm searching for the best way how I can include also the crendentials of my admintest user. Do I have to 'nest' it with a second withCredentials part or can I add again a usernamePassword 'array'?

推荐答案

当然,您可以使用一个withCredentials块将多个凭据分配给不同的变量.

Sure, you can use one withCredentials block to assign multiple credentials to different variables.

withCredentials([
    usernamePassword(credentialsId: credsId1, usernameVariable: 'USER1', passwordVariable: 'PASS1'),
    usernamePassword(credentialsId: credsId2, usernameVariable: 'USER2', passwordVariable: 'PASS2')
]){
    //...
}

这篇关于如何在Jenkins Pipeline中的withCredentials中使用多个凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆