2017-11-24 60 views
3

선언 용 jenkins 파이프 라인에 다음 단계를 수행합니다. library폴더에서 제공하는 스크립트를 libraryResource를 사용하여 만듭니다. 이 스크립트에는 내 autobuild 사용자 및 일부 admintest 사용자의 자격 증명이 포함되어 있습니다.Jenkins Pipeline의 withCredentials에서 다중 자격 증명을 사용하는 방법

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 사용자의 crendentials도 포함시킬 수있는 가장 좋은 방법을 찾고 있습니다. 두 번째로 withCredentials 부분을 '중첩'해야합니까, 아니면 usernamePassword '배열'을 다시 추가 할 수 있습니까?

답변

7

물론 하나의 withCredentials 블록을 사용하여 여러 자격 증명을 다른 변수에 할당 할 수 있습니다.

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