# .gitlab-ci.yml
image: alpine:latest
only on branches:
rules:
- if: '$CI_COMMIT_TAG == null'
script:
- echo only on branches
- env
only on tags:
rules:
- if: '$CI_COMMIT_TAG != null'
script:
- echo only on tags
- env
job:
script: echo "Hello, Rules!"
rules:
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != $CI_DEFAULT_BRANCH
when: never
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/
when: manual
allow_failure: true
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
docker build:
script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- Dockerfile
when: manual
allow_failure: true
- if any found rule is evaluated to be true ever rule after it is not evaluated anymore
- e.g. first rule adds pipeline job then job/pipeline is definitly added, even if there is a later rule excluding it
- e.g. first rule found to be evaluated to true is a rule containing
when: never
means nothing is added and also all rules after are not considered anymore bec this rules was evaluated true
- that implies: order of rules matter
# https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines
# Tell GitLab to only run one pipeline at a time for a commit:
# - a branch pipeline when a merge request is not open for the branch
# - a merge request pipeline when a merge request is open for the branch
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
# rules: # examples
- if: $CI_COMMIT_BRANCH == "my-branch-name-xyz"