This is a follow up to Should a pipeline fail if early termination is desired?. 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 Bump may or may not bump the version number. Is there a way to have the Version Bump pass regardless of whether the number was bumped, and to have Publish run conditionally if the version was bumped?

1 Answer 1


To paraphrase:

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_failure keyword on gitlab jobs.

If you're using semantic-release, the decision to cut a new release is done by default with the commit-analyzer plugin, 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 nextVersion > latestVersion.

If nextVersion > latestVersion -> publish

else exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.