Dmitry Bondar
Dmitry Bondar

Reputation: 1

How to set up parent pipeline for different triggers commit messages and web button?

I have parent with child pipeline I want to add manual trigger by button in webui and trigger by commit message.

Like trigger on push commit: message “job-1” run child pipeline job-1

message “job-2” run child pipeline job-2

message “job-3” run child pipeline job-3

message “job-all” run child pipeline step by step job-1 than job-2 than job-3

And I need to run via webui jobs separate job-1 or job-2 or job-3

And run via web up all job step by step job-1 → job-2 → job-3

gitlab-runner -v Version: 17.7.0

But when my pipelines execute it works correct by stages, but in the finish I got message status blocked.

How to do it correctly? Kindly ask to help. Thanks!

.gitlab-ci.yml
├── job-1/.gitlab-ci.yml
├── job-2/.gitlab-ci.yml
└── job-3/.gitlab-ci.yml

parent gitlab-ci.yml

.rules_template: &rules_template
  rules:
    - if: '$CI_PIPELINE_SOURCE == "manual"'
      when: manual
    - if: '$CI_PIPELINE_SOURCE == "push"'
      when: always
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: always

stages:
  - run_pipelines

run_job-1:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ /job-1/i'
      when: always
    - if: '$CI_COMMIT_MESSAGE =~ /job-all/i'
      when: always
    - when: manual  
  trigger:
    include:
      - local: job-1/.gitlab-ci.yml
    strategy: depend

job-2:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ /job-2/i'
      when: always
    - if: '$CI_COMMIT_MESSAGE =~ /job-all/i'
      when: always
    - when: manual 
  trigger:
    include:
      - local: job-2/.gitlab-ci.yml
    strategy: depend
  needs:
    - job-1

job-3:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ /job-3/i'
      when: always
    - if: '$CI_COMMIT_MESSAGE =~ /job-all/i'
      when: always
    - when: manual
  trigger:
    include:
      - local: job-3/.gitlab-ci.yml
    strategy: depend
  needs:
    - job-2

job_all:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ /job-all/i'
      when: always
    - when: manual
  trigger:
    include:
      - local: job-1/.gitlab-ci.yml
      - local: job-2/.gitlab-ci.yml
      - local: job-3/.gitlab-ci.yml
    strategy: depend

job1-job-3 almost same like:

stages:
  - build
  - deploy
build:
  stage: build
  script:
    - echo "Build..."
deploy:
  stage: deploy
  script:
    - echo "Deploy…"    

Part 2.

I would like to add some examples, I build Linux image build system for some Linux distro. And trigger with commit message ununtu-1 run ubuntu-1, ubuntu-2 run ubuntu-2 and same for ubuntu-3. Commit message with ununtu-all run all 3 pipelines (version 1, 2 and 3). I wrote some app in python to trigger each pipeline via API. Also i need a manual trigger via buttons in webui Gitlab, for same schema.

And now i need to add email notify via microsoft apps. it’s a problem too, no password authorization.

Could you please check my parent pipeline. I think clearly write what i should get. thanks!

About locking pipeline i mean this like in a image.

here is the full code of my parent pipeline:

parent pipeline:

# Parent pipeline:

.rules_template: &rules_template
  rules:
    - if: '$CI_PIPELINE_SOURCE == "manual"'
      when: manual
    - if: '$CI_PIPELINE_SOURCE == "push"'
      when: always
    - if: '$CI_PIPELINE_SOURCE == "web"'
      when: always
  allow_failure: true
  variables:
    TEAMS_WEBHOOK_URL: $TEAMS_WEBHOOK_URL

stages:
  - run_pipelines

manual_run_ubuntu_1:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - when: manual
  trigger:
    include:
      - local: ubuntu_1/.gitlab-ci.yml
    strategy: depend

manual_run_ubuntu_2:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - when: manual
  trigger:
    include:
      - local: ubuntu_2/.gitlab-ci.yml
    strategy: depend

manual_run_ubuntu_3:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - when: manual
  trigger:
    include:
      - local: ubuntu_3/.gitlab-ci.yml
    strategy: depend

manual_run_all:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - when: manual
  trigger:
    include:
      - local: ubuntu_1/.gitlab-ci.yml
      - local: ubuntu_2/.gitlab-ci.yml
      - local: ubuntu_3/.gitlab-ci.yml
    strategy: depend

run_ubuntu_1:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ /ubuntu-1/i'
      when: always
    - if: '$CI_COMMIT_MESSAGE =~ /ubuntu-all/i'
      when: always
  trigger:
    include:
      - local: ubuntu_1/.gitlab-ci.yml
    strategy: depend

run_ubuntu_2:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ /ubuntu-2/i'
      when: always
    - if: '$CI_COMMIT_MESSAGE =~ /ubuntu-all/i'
      when: always
  trigger:
    include:
      - local: ubuntu_2/.gitlab-ci.yml
    strategy: depend

run_ubuntu_3:
  stage: run_pipelines
  <<: *rules_template
  rules:
    - if: '$CI_COMMIT_MESSAGE =~ /ubuntu-3/i'
      when: always
    - if: '$CI_COMMIT_MESSAGE =~ /ubuntu-all/i'
      when: always
  trigger:
    include:
      - local: ubuntu_3/.gitlab-ci.yml
    strategy: depend

blocked pipeline image this is a mean pipiline blocked and needs to run manually.

Upvotes: 0

Views: 37

Answers (0)

Related Questions