2017-11-24 62 views
3

私は宣言型ジェンキンスパイプラインで次のステップを実行します: 私はresources/フォルダからlibraryResourceを使用して作成されたスクリプトを作成します。このスクリプトには、私のautobuildユーザーとadmintestユーザーのための資格情報が含まれています。Jenkinsパイプラインで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ユーザーのクレデンシャルをどのように含めることができるかを調べるための最善の方法を探しています。 2番目のwithCredentials部分に「ネスト」する必要がありますか、usernamePassword「配列」を再度追加することはできますか?

答えて

7

もちろん、1つのwithCredentialsブロックを使用して、複数の資格情報を異なる変数に割り当てることができます。

withCredentials([ 
    usernamePassword(credentialsId: credsId1, usernameVariable: 'USER1', passwordVariable: 'PASS1'), 
    usernamePassword(credentialsId: credsId2, usernameVariable: 'USER2', passwordVariable: 'PASS2') 
]){ 
    //... 
} 
関連する問題