Skip to content

Instantly share code, notes, and snippets.

@VerosK
Last active March 23, 2021 08:33
Show Gist options
  • Save VerosK/03fd34fa0e06ae9318cb1d7659100c44 to your computer and use it in GitHub Desktop.
Save VerosK/03fd34fa0e06ae9318cb1d7659100c44 to your computer and use it in GitHub Desktop.
Testing Gitlab CI rules
stages:
- debug
- test
- build
- deploy
variables:
SOME_VARIABLE: present
debug:
stage: debug
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push'
- when: always
script:
- export 1>&2
.tests:
stage: test
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
.build:
stage: build
rules:
- if: # ensure build is ran on merge request to master
$CI_PIPELINE_SOURCE == 'merge_request_event'
&& $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'master'
when: always
- if: # ensure build is ran on merge_request to devel
$CI_PIPELINE_SOURCE == 'merge_request_event'
&& $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'devel'
when: always
- if: # ensure build is ran on merge target to devel
$CI_PIPELINE_SOURCE == 'push'
&& $CI_COMMIT_REF_NAME == 'devel'
when: always
- if: # ensure build is ran on merge target to master
$CI_PIPELINE_SOURCE == 'push'
&& $CI_COMMIT_REF_NAME == 'master'
when: always
- if: # enable manual build run
$CI_PIPELINE_SOURCE == 'merge_request_event'
when: manual
- when: never
.deploy:
stage: deploy
Test Lorem:
stage: test
extends: .tests
artifacts:
expire_in: 1week
paths:
- artifacts
script:
- echo OK
- export 1>&2
Build Lorem:
stage: build
extends: .build
artifacts:
expire_in: 1week
paths:
- artifacts
script:
- mkdir -p artifacts
- echo Lorem ipsum dolor sit amet > artifacts/lorem-ipsum.txt
- export > artifacts/exports.txt
Deploy Lorem (Staging):
stage: deploy
needs:
- Build Lorem
rules:
- if: $CI_COMMIT_BRANCH == 'devel'
environment:
name: staging
script:
- ls -l artifacts 1>&2
Deploy Lorem (Production):
stage: deploy
needs:
- Build Lorem
rules:
- if: $CI_COMMIT_BRANCH == 'master'
when: manual
environment:
name: production
script:
- ls -l artifacts 1>&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment