Satyam Pandit
Satyam Pandit

Reputation: 1

Gitlab must execute either one of the 2 job groups and succeed if all jobs in the executing job group succeeds

I have a scenario when I'm trying to merge code from DEV branch to QA branch. This is very specific to merging in QA branch only.

I have 4 jobs that are separated by 2 groups in gitlab yml file.

Group 1: Job1_group1, Job2_group1 Group 2: Job1_group2, Job2_group2

I want either group1 or group 2 to execute, but the option to execute which group must be in the hands of the developer who creates the merge request and is trying to merge in QA. The pipeline must succeed if the selected group executes all its jobs successfully without any failure or warnings, else the entire pipeline should fail.

How can I achieve this?

stages:
  - group1
  - group2
  - finalize

#Group 1 - Job 1
group1_job1: 
  stage: group1 
  script: 
    - echo "Executing Group 1 Job 1" 
  rules: 
    - if: $EXECUTE_GROUP == "group1" 
      when: on_success 
    - when: never 
  allow_failure: false

#Group 1 - Job 2
group1_job2: 
  stage: group1 
  script: 
    - echo "Executing Group 1 Job 2" 
  rules: 
    - if: $EXECUTE_GROUP == "group1"
      when: on_success 
    - when: never 
  allow_failure: false

#Group 2 - Job 1
group2_job1: 
  stage: group2 
  script: 
    - echo "Executing Group 2 Job 1" 
  rules: 
    - if: $EXECUTE_GROUP == "group2" 
      when: on_success 
    - when: never 
  allow_failure: false

#Group 2 - Job 2
group2_job2: 
  stage: group2 
  script: 
    - echo "Executing Group 2 Job 2" 
  rules: 
    - if: $EXECUTE_GROUP == "group2"
      when: on_success 
    - when: never 
  allow_failure: false

#Finalize Job
finalize: 
  stage: finalize 
  script: 
    - echo "Pipeline finalized successfully" 
  rules: 
    - when: always 
  needs: 
    - group1_job1 
    - group1_job2 
    - group2_job1 
    - group2_job2

This is something that I tried, but problem is $EXECUTE_GROUP environment variable which I need to set beforehand. I want the group selection to be done at the time of merge.

Upvotes: 0

Views: 11

Answers (0)

Related Questions