I’m trying to configure my .config-ci.yml so that certain jobs run when commits are made on specific branches. For example, I would like “dev-job” to run when I commit to the “development” branch. What would be the best way to accomplish this? Would something like the following work:
stages:
- dev
dev-job:
stage: dev
only:
- if: $CI_COMMIT_BRANCH == 'development
script:
- echo "This runs when a commit is made in the 'development' branch."
I think you probably want to use rules here, like this:
stages:
- dev
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
when: never
- when: always
dev-job:
stage: dev
rules:
- if: '$CI_COMMIT_BRANCH == "development"'
when: always
- when: never
script:
- echo "This runs when a commit is made in the 'development' branch."
I reviewed some situations like mine and found that you need to reference merge_request in order to use the $CI_MERGE_REQUEST_TARGET_BRANCH_NAME variable:
stages:
- dev
dev-job:
stage: dev
only:
refs:
- merge_request
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH
script:
- echo “This runs when a commit is made in the ‘development’ branch.”