GitLab CI execute deploy stage after one of multiple build stages is done

Viewed 213

I have four build stages, which are operated manually. What I'd like is to execute the deploy stage, after one build stage is finished. Right now my implementation only works when all four build stages are finished.

Use case: Dev klicks on the environment he wants to build. After build is done, it is deployed to the systems. Deploy should start automatically after build is finished

Q: Is there a way to execute the deploy stage after only one build is done?

My implementation of the build pipelines (simplified):

production:
  stage: env
  script:
    - echo build one
  when: manual
  allow_failure: false

production2:
  stage: env
  script: 
    - echo build two
  when: manual
  allow_failure: false

staging:
  stage: env
  script: 
    - echo build three
  when: manual
  allow_failure: false

staging2:
  stage: env
  script:
    - echo build four
  when: manual
  allow_failure: false

This is my deploy stage

build:
  stage: build
  needs: [production, production2, staging, staging2]
  when: on_success

  script:
    - echo do deploy stuff

Many thanks and I wish you a nice day

2 Answers

Maybe something like this help?

build:
  stage: build
  needs:
    - job: production
      optional: true
    - job: production2
      optional: true
    - job: staging
      optional: true
    - job: staging2
      optional: true
  when: on_success
  script:
    - echo do deploy stuff

So far I've only found a solution that works.

stages:
  - env
  - connections
  - build

production:
  stage: env
  script:
    - echo build one
  when: manual
  allow_failure: false

production2:
  stage: env
  script: 
    - echo build two
  when: manual
  allow_failure: false

staging:
  stage: env
  script: 
    - echo build three
  when: manual
  allow_failure: false

staging2:
  stage: env
  script:
    - echo build four
  when: manual
  allow_failure: false

# Connections 
  
run:build:production:
  extends: .build
  stage: connections
  needs:
    - job: production
    
run:build:production2:
  extends: .build
  stage: connections
  needs:
    - job: production2

run:build:staging:
  extends: .build
  stage: connections
  needs:
    - job: staging

run:build:staging2:
  extends: .build
  stage: connections
  needs:
    - job: staging2 

.build:
  stage: build
  script:
    - echo do deploy stuff  
Related