Our .gitlab-ci.yml
file has a deploy to prod triggered by a MR from the develop branch to the main branch.
Is there a way to skip the deploy to prod if only tests changed? Incidentally, our tests are not run on the runner, we run them locally.
Our .gitlab-ci.yml
file has a deploy to prod triggered by a MR from the develop branch to the main branch.
Is there a way to skip the deploy to prod if only tests changed? Incidentally, our tests are not run on the runner, we run them locally.
I’m not sure I follow. Can you share an example of the current configuration?
if only tests changed
Tests were edited/updated in the source code? rules:changes
could be an option to experiment with.
I guess another way of wording it would be… Don’t deploy to prod if the MR only includes non-essential changes like changes to the README.md, or changes to the unit tests. Though now, that I think about it, this may not be achievable. It may be better to just make deploys to prod manual…
Either rules:changes or rules:changes:compare_to. You can also use variables in rules:changes to create more dynamic rules.
deploy-to-prod:
script:
- echo "Deploying to prod"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- backend/**/*
- frontend/**/*
If rules are not sufficient, you can go one step further, and build the deployment gate into the job script
itself, e.g. by getting a diff of the changed files, and determine if there are changes that warrant the deployment trigger. Or call exit 1
to signal skipping the deployment, but this needs allow_failure: true
on the job. Alternatively, just log the skip and run exit 0
. CI/CD pipeline - get list of changed files - #16 by anarcat has a few examples in the discussion.