The changeset
declaration causes a Jenkins pipeline stage to execute when files matching the changeset
specification are changed between runs of the pipeline.
This is all very well and good, but if it's the first run of the pipeline, then this will be skipped as no changes are detected.
How do you write a when
condition that is triggered on a change of files or the first run of the pipeline?
CodePudding user response:
You can do something like the below.
stage('Example Deploy') {
when { expression {
return (currentBuild.changeSets.size() > 0 || currentBuild.number == 1)
}
}
steps {
echo 'RUN==================='
}
}
Update
With changeset
when {
anyOf {
changeset '**/*.c'
expression {
currentBuild.number == 1
}
}
}