Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use multiple 'workflows' in gitlab ci?

Lets Imagine I want to have 2 different CI Pipelines in gitlab. The first one should start with every push on any branch the other one only when the commit title ends with deploy.

How do I realise that?

So my Idea:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.gitlab-ci.yml

stages:
  - pre
  - build


include:
  - local: ci/a.gitlab-ci.yml
  - local: ci/b.gitlab-ci.yml

a.gitlab-ci.yml

workflow:
  rules:
  # only triggered by "-deploy" at the end of commit 
    - if: $CI_COMMIT_TITLE == /-deploy$/ 

test-job1:
  stage: pre
  script:
    - echo "Workflow a runs pre."
  tags:
    - x86

test-job2:
  stage: build
  script:
    - echo "Workflow a runs build."
  tags:
    - x86

b.gitlab-ci.yml

workflow:
  rules:
  # only triggered if commit does not end with  "-deploy"  
    - if: $CI_COMMIT_TITLE =~ /-deploy$/ 

test-job1:
  stage: pre
  script:
    - echo "Workflow b runs pre."
  tags:
    - x86

test-job2:
  stage: build
  script:
    - echo "Workflow b runs build."
  tags:
    - x86

>Solution :

To achieve the effect you want, your best bet would be to use include:rules: for this instead of workflow:rules:.

I believe you also may have a small error in the regex matching rule. You probably wanted to be using the regex match operator (=~ i.e., does match the pattern) in the first case and the negative match re operator (!~ i.e., does not match the pattern) in the second case.

include:
  - local: ci/a.gitlab-ci.yml
    rules:
      - if: '$CI_COMMIT_TITLE =~ /-deploy$/'
  - local: ci/b.gitlab-ci.yml
    rules:
      - if: '$CI_COMMIT_TITLE !~ /-deploy$/'

Then remove the workflow:rules: from each respective template.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading