I want my pipeline to run when MR are accepted and merged to master, when commits are made direct to master, or on manual runs. But only when a subset of files change because it’s a ‘gulp’ pipeline for a website.
But I made a commit to master, that changed website/js/controller/controller-foo.js, and the pipeline has not run - nothing new listed in “pipelines” or “jobs”.
each merged MR creates a merge commit in a target branch (unless you are using Fast-forward merge) which triggeres a branch pipeline. So the first rule doesn’t make any sense. The CI_BUILD_REF_NAME doesn’t even exist according to Predefined variables reference | GitLab
If master is your default branch you can also use CI_DEFAULT_BRANCH just in case it changes in the future.
Also if you want to include changes in sub-directories as well, you need to use **/* instead of just *
By manual do you mean run from UI? Because currently the job is marked as manual if the commit is on other branch than master.
So it could look like this:
rules:
# run on any commit to default branch
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"'
changes:
- website/css/**/*
- website/components/**/*
- website/directives/**/*
- website/template/**/*
- website/js/**/*
- website/package.json
allow_failure: true
# run on commits to other branches
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: manual
I’ll try reworking changes entries to include double stars - to be clear if I want to match changes in website/js/foo/bar.js and website/js/baz.js I’ll need - website/js/**/* and - website/js/* right ?
Do you think - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"' would match both MR being accepted and manual commits to master then ? Under Settings, General, Merge requests we’ve got “Merge commit” selected.
website/js/**/* should be for directory and all its subdirectories, no need for website/js/*, but as always test if it works as documentation says
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH is something I use quite often in Jobs and I know they run after MR is merged as well as after direct commit. The $CI_PIPELINE_SOURCE == "push" should work as well.