I tried to use this Conditional multi step plugin and wrote the grrovy script for DSL however when i bootstrap using this code, the steps listed are outside before the conditional block, what am i doing wrong here?
Code:
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);
}
};
So jenkins job which gets created is shown as
npm install
mkdir buildArchive
Conditional step
Instead of
Conditional step
{
npm install
mkdir buildArchive
}
What i am doing wrong here?
When you generate a job with your steps configuration
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')
}
}
}
}
the result seems fine:
In my experience, when you have any issues with the Job DSL syntax and its results, a good approach is to diff the config.xml of your job:
When I started to use the Job DSL with no experience with groovy - especially closures ;) - I had a lot of simmilar issues when I tried to extract job configuration blocks into methods like in your case. This is what helped me to understand what is really going on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.