Bishop
Bishop

Reputation: 131

Run Gitlab CI job on merge to master for only changes

Is there a way to reliably execute a job on merge to master only when there are changes to the script? I'm using

vm-build:
  image: 
    name: path_to_image
  stage: vm-deploy
  only:
    changes:
      - job.gitlab-ci.yml
    refs:
      - master
  except:
    - schedules
    - triggers
  script:
    - ansible-playbook playbooks/pb_job.yml
  tags:
    - docker

but it seems to execute 'job' on different commits to master where job.gitlab-ci.yml hasn't changed. I haven't found a rhyme or reason to why though.

Upvotes: 1

Views: 2279

Answers (1)

Aleksey Tsalolikhin
Aleksey Tsalolikhin

Reputation: 1668

The following .gitlab-ci.yml runs only on changes to the file jobs.gitlab-ci.yml on the master branch:

myjob:
  script:
    - echo I am a CI job
  only:
      changes:
        - job.gitlab-ci.yml
      refs:
        - master

It does not run on changes to any other file in the master branch.

Upvotes: 3

Related Questions