Why didn't my pipeline run

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.

So I have

default:
  image: node:12-stretch

package:
  script: 
    - echo build on $CI_COMMIT_BRANCH
  after_script:
    - cd website
  rules:
    # MR accepted and merged 
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_BUILD_REF_NAME == "master"'
      changes:
        - website/css/*
        - website/components/*
        - website/directives/*
        - website/template/*
        - website/js/*
        - website/package.json
      allow_failure: true
    - if: '$CI_COMMIT_BRANCH == "master"'
      changes:
        - website/css/*
        - website/components/*
        - website/directives/*
        - website/template/*
        - website/js/*
        - website/package.json
      allow_failure: true
    - if: '$CI_COMMIT_BRANCH != "master"'
      when: manual

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”.

We’re using gitlab.com rather than hosted.

Hi @tomchiverton

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

This was deprecated and renamed : Rename Gitlab CI variable CI_BUILD_REF_NAME -> CI_COMMIT_REF_NAME · Issue #273 · example42/psick · GitHub

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 :slight_smile:

- 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.

Hurrah !

I pushed a new change to master directly, website/directives/foo/bar.js and the pipeline ran this time :slight_smile:

1 Like