WoJ
WoJ

Reputation: 30044

How to run a pipeline only on changes in a specific branch?

I am looking through the documentation back and forth and cannot find how to configure my .gitlab-ci.yml so that the content is executed only on a change in the branch mqtt_based and not in the default master.

I was hoping that adding an only entry for each section would be enough (I was hoping for a global setting), but this did not help (the pipeline was not started when the mqtt_based branch was changed)

variables:
  BRANCH: "mqtt_based"

stages:
  - build
  - deploy

job:build-back:
  stage: build
  script:
    - cd back
    - docker build --build-arg COMMIT=${CI_COMMIT_SHORT_SHA} --build-arg DATE=$(date --iso-8601=seconds) -t registry.XXX/homemonitor-back:latest -t registry.XXX/homemonitor-back:${CI_COMMIT_SHORT_SHA} -f Dockerfile .
  only:
    - $BRANCH
(...)

Upvotes: 1

Views: 1807

Answers (1)

Brad Pitt
Brad Pitt

Reputation: 416

You need to use 'refs' after 'only'. Something like this

only:
  refs:
    - mqtt_based

Documentation: https://docs.gitlab.com/ce/ci/yaml/#onlyexcept-advanced

Upvotes: 1

Related Questions