0
プログラミングは豊富ではありませんが、習得するのは楽しいです。jenkinsfile groovyスクリプトでローカル変数をロードする
質問:jenkinsfileビルドのエラーデータは、ファイル内でローカルで正常に動作しますが、.groovyスクリプトとしてロードされると、「サイレント」に失敗します。ロードされたGroovyスクリプトのチャンネルにこの情報を投稿する理由/方法に関するガイダンスはありますか?
[cure-deploy] Running shell script
+ introduce error here
/home/jenkins/remote/workspace/blablabla/script.sh: line 2: introduce: command not found
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // timeout
[Pipeline] load
[Pipeline] { (ci/curlBuildFailed.groovy)
[Pipeline] }
[Pipeline] // load
[Pipeline] }
[Pipeline] // wrap
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // load
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
注:上記のランニング
はJenkinsfile
#!groovy
properties([[$class: 'jenkins.model.BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '5', artifactNumToKeepStr: '5']]])
node('node_name'){
def err = null
currentBuild.result = "SUCCESS"
role_name = "deploy"
try {
timeout(60){
stage "${role_name}"
deleteDir()
checkout scm
sh 'introduce error here'
}
}
catch (error){
err = error
currentBuild.result = "FAILURE"
load "ci/curlBuildFailed.groovy"
}
finally {
if (err){
throw err
}
}
}
curlBuildFailed.groovy
sh "curl -i -X POST -d \'payload={" +
"\"text\": \"${env.JOB_NAME}: ${env.BUILD_URL} - build failed with ${err}!\", " +
"\"username\": \"JenkinsBot\", " +
"\"icon_url\": \"$FAIL_BUILD\"}\' $DEVOPS_NOTIFY_URL "
これを生成
curlBuildFailed.groovy
の内容を同じ 位置にドロップすると、load "ci/curlBuildFailed.groovy"
という出力が作成され、目的の 出力が作成されます。- 犯人を で
${err}
に絞り込みました。その変数を削除すると、ただちに が問題なく表示されます。 - (これに類似した約30の役割がありますので、重複したコードを抽象的な構造に維持しようとしています)
- これは数時間前から検索されていますが、 Aまだ解決:
- jenkins plain catch blocks
- don't think I need a 'returns this;' but who knows
- Passing Variables in Jenkinsfile Closure
はお時間をいただき、ありがとうございます! - Sam