Can I create a pipeline stage which unconditionally passes but one in which a subsequent stage conditionally runs?
This is a follow up to https://devops.stackexchange.com/q/15709/18965 . In that question, I'm asking about best practices and whether this request is sound. In this, I just need to know how best to get it done.
Normally a pipeline breaks down into stages such that each stage has one or more jobs. In order to stop the pipeline from running conditionally, you simply fail that stage of the pipeline.
For example let's assume I have a pipeline with four stages,
[Build] -> [Test] -> [Version Bump] -> [Publish]
Now, let's assume the
Version Bumpmay or may not bump the version number. Is there a way to have the
Version Bumppass regardless of whether the number was bumped, and to have Publish run conditionally if the version was bumped?
Is there a way to have (a job) pass regardless of whether the (something has changed), and to have (another job) run conditionally if (something was actually changed)?
The first part (run a job whether something changes or not) can be done by either changing the script so that it returns a zero exit code (success), even if something hasn't changed (which can be interpreted as "fail"), or you can continue the pipeline regardless of whether that job has failed or not. This is typically done with the
allow_failurekeyword on https://docs.gitlab.com/ee/ci/jobs/job_control.html#rules-examples .
If you're using
semantic-release, the decision to cut a new release is done by default with the https://github.com/semantic-release/commit-analyzer/ , which analyses every commit in the change to determine, according to your release policy, whether a new version is required.
In your particular case you're dealing with version numbers. So the version changes, publish. Else, do not publish. So a common trick is to compare the
nextVersion(the version you have computed in this pipeline) with the existing tags on the repo or published versions of the artifact to determine whether
else exit 0