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

查看:38
本文介绍了如何在 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 'array'?

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天全站免登陆