[英]Jenkins conditionalstep groovy script
我嘗試使用此條件多步驟插件並為DSL編寫了grrovy腳本,但是當我使用此代碼進行引導時,列出的步驟不在條件塊之前,所以我在這里做錯了什么?
參考: https : //jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.step.StepContext.conditionalSteps
碼:
def configSeed(environment, slaveLabel) {
{ it ->
parameters {
stringParam('BUILD_REQUIRED', 'true', '');
}
scm {
git {
remote {
name('origin');
url('xyz');
refspec('$GERRIT_REFSPEC');
credentials('xyz');
}
branch('$GERRIT_BRANCH');
strategy {
gerritTrigger();
}
}
}
steps {
conditionalSteps {
condition {
stringsMatch('${BUILD_REQUIRED}', 'true', false)
}
runner('Fail')
steps {
environmentVariables {
envs(environment);
}
batchFile('''
call npm install
''');
batchFile('''
call mkdir buildArchive
''');
}
}
}
publishers {
wsCleanup {
includePattern('build/**')
}
}
wrappers {
preBuildCleanup();
timeout {
noActivity(300);
abortBuild();
}
}
label(slaveLabel);
}
};
因此,創建的詹金斯工作顯示為
npm install
mkdir buildArchive
Conditional step
代替
Conditional step
{
npm install
mkdir buildArchive
}
我在這里做錯了什么?
使用步驟配置生成作業時
job('foobar') {
steps {
conditionalSteps {
condition {
stringsMatch('${BUILD_REQUIRED}', 'true', false)
}
runner('Fail')
steps {
environmentVariables {
envs(FOO: 'bar', TEST: '123')
}
batchFile('call npm install')
batchFile('call mkdir buildArchive')
}
}
}
}
結果似乎很好:
以我的經驗,當您對Job DSL語法及其結果有任何疑問時,一個好的方法是對作業的config.xml進行比較:
當我開始使用沒有groovy經驗的Job DSL時-尤其是閉包;)-當我嘗試將作業配置塊提取到您所使用的方法中時,我遇到了很多類似的問題。 這就是幫助我了解實際情況的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.