基本的には、sh
のステップが行うことです。あなたは変数に結果をキャプチャしていない場合は、あなただけで実行できます。
sh "./build"
スクリプトがゼロ以外の終了コードをreurns場合、これは終了します。
あなたが最初のものを行う必要があり、その結果をキャプチャする必要がある場合は、あなたが仕事
stage('Building') {
def result = sh returnStatus: true, script: './build.sh'
if (result != 0) {
echo '[FAILURE] Failed to build'
currentBuild.result = 'FAILURE'
// do more stuff here
// this will terminate the job if result is non-zero
// You don't even have to set the result to FAILURE by hand
sh "exit ${result}"
}
}
を終了するには、シェルの手順を使用することができますが、次はあなたに同じを与えるが、より正気思われますdo
stage('Building') {
try {
sh './build.sh'
} finally {
echo '[FAILURE] Failed to build'
}
}
コードでリターンを呼び出すこともできます。しかし、あなたがstage
の中にいる場合、それはその段階から戻ってくるだけです。だから、
stage('Building') {
def result = sh returnStatus: true, script: './build.sh'
if (result != 0) {
echo '[FAILURE] Failed to build'
currentBuild.result = 'FAILURE'
return
}
echo "This will not be displayed"
}
echo "The build will continue executing from here"
は文句を言わない仕事を終了しますが、
stage('Building') {
def result = sh returnStatus: true, script: './build.sh'
}
if (result != 0) {
echo '[FAILURE] Failed to build'
currentBuild.result = 'FAILURE'
return
}
意志。
出典
2016-12-01 20:14:11
Rik
をジェンキンズ2.89.3では、これは誤りです: 'org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:スクリプトは、新しいを使用することはできませんhudson.AbortException java.lang.String' –
サンドボックスモードが有効になっているように見え、その例外をスローすることは禁じられています。奇妙な、しかし、サンドボックスモードを無効にするのは、そのトリックを行う必要があります。 – Jazzschmidt
また、Manage Jenkins> In-process Script Approvalを使用して使用を許可することもできます – Jazzschmidt