Skip gitlab pipeline job if no changes in files and last pipeline for that job is successful

Viewed 812

I have a Gitlab Pipeline configured in this way: Build >> Test >> Release

What I want to achieve is:

Skip test if:

  1. Test job for the same branch has succeeded in the last pipeline for the same branch run AND;
  2. No changes in certain files

Also always run test if:

  1. Test job for the same branch has failed in the last pipeline for the same branch run OR;
  2. This is it's first run on the same branch ever (no previous pipelines), OR;
  3. There are changes in certain files (same files as above)

Is this possible? If yes, how?

1 Answers

If you don't mind another tool we support this functionality with Reliza Hub for any CI/CD (disclaimer: I'm working on the tool).

Essentially, you would add some yaml like following (this is a working sample from one of demo projects which is building a helm chart):

         - # get latest completed release to see if there are diffs in helm chart
         - do_helm_release="true"
         - last_commit=$(docker run --rm relizaio/reliza-cli getlatestrelease -i $RELIZA_API_ID -k $RELIZA_API_KEY --branch $CI_COMMIT_REF_NAME| jq -r ".sourceCodeEntryDetails.commit")
         - if [ ! -z "$last_commit" ]; then changes=$(git log $last_commit..$CI_COMMIT_SHA helm/ | wc -l); if [ $changes -eq 0 ]; then do_helm_release="false"; fi; fi
         - echo "do helm release = $do_helm_release"
         - if [ "true" == "$do_helm_release" ]; then ...

Later in your yaml you would submit release details to Reliza Hub. Here is a base sample for that - https://github.com/relizaio/reliza-hub-integrations/blob/master/GitLab/standard-docker-registry/.gitlab-ci.yml

Reliza Hub would automatically discard any failed releases so you would only do Git comparison with successful releases.

If you want to do build but skip test, you can leverage approval logic where automated process sets certain approvals and then you get builds only with certain required approvals to do comparison with. See here for some more details - https://worklifenotes.com/2020/04/09/approvals-for-any-ci-cd-in-reliza-hub-demo-video/

Community support for Reliza Hub - https://discord.gg/UTxjBf9juQ

Related