2016-11-07 4 views
0

JenkinsでwithCredentialsを使用して渡されたシェルコマンドをトリガーする関数。たとえば、代わりのジェンキンスのジョブステップ内で呼び出すpropperの道になりますどのようなものGroovyが機能するためのシェルコマンド

def performWithCredentials(command_block){ 
    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'amazon', 
         usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) { 
      //Passed command_block 
     } 
} 

のように、この

withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'amazon', 
         usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) { 
      //Shell commands block 
      sh """ 
      echo 'hello world' 
      echo 'Good bye' 
      """ 
     } 

トリガそれをやって?

おかげと歓声

答えて

0

ただwithCredentialsにブロックを渡します。

def performWithCredentials(command_block){ 
    withCredentials([[$class: 'UsernamePasswordMultiBinding', 
         credentialsId: 'amazon', 
         usernameVariable: 'USERNAME', 
         passwordVariable: 'PASSWORD']], command_block) 
} 
+0

あなたはアップデートを見て、実際にそれを呼び出すことを提案できますか?ありがとう – OdinRW

0

また、あなたが

performWithCredentials(delegate) { 
    withCredentials([[$class: 'UsernamePasswordMultiBinding', 
     credentialsId: 'amazon', 
     usernameVariable: 'USERNAME', 
     passwordVariable: 'PASSWORD']]) { 
     delegate() 
    } 
} 

にそれを回して、あなたも、ファイルを作ることができ

performWithCredentials { 
    ... 
    <your code here> 
    ... 
} 

のようにそれを呼び出すことができますgroovy/pipelines

で独自のデリゲートを書くことができperformWithCredentials.groovy関数call(..)tutorial)、それを$JENKINS_HOME/workflow-libs/に格納します。 ジェンキンスを再起動して、それをグローバルに利用可能にする

関連する問題