How to use multiple credentials in withCredentials in Jenkins Pipeline

I have the next step in my declarative jenkins project: I am creating a script that comes from my folder resources/using libraryResource. This script contains credentials for my user autobuildand for some user 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 "
                        }

                    }

                }   

It works great. I can use my user autobuild. Now I am looking for the best way how I can also include my user capabilities admintest. Should I "nest" it with the second part, withCredentialsor can I add an array again usernamePassword?

+15
source share
2 answers

, withCredentials .

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

,

org.codehaus.groovy.control.MultipleCompilationErrorsException: : WorkflowScript: 54: "withCredentials" .

0

Source: https://habr.com/ru/post/1689787/


All Articles