How do I make a stage pass only if one or more jobs succeed in GitLab CI?

Viewed 637

I have a .gitlab-ci.yml that looks like this:


image: "python:3.7"

.python-tag:
  tags:
    - python

before_script:
  - python --version
  - pip install -r requirements.txt
  - export PYTHONPATH=${PYTHONPATH}:./src
  - python -c "import sys;print(sys.path)"

stages:
  - Static Analysis
  - Local Tests
  - Integration Tests
  - Deploy

mypy:
  stage: Static Analysis
  extends:
    - .python-tag
  script:
    - mypy .

pytest-smoke:
  stage: Local Tests
  extends:
    - .python-tag
  script:
    - pytest -m smoke

int-tests-1:
  stage: Integration Tests
  when: manual
  allow_failure: false
  trigger:
    project: tests/gitlab-integration-testing-integration-tests
    strategy: depend

int-tests-2:
  stage: Integration Tests
  when: manual
  allow_failure: false
  trigger:
    project: tests/gitlab-integration-testing-integration-tests
    strategy: depend

deploy:
  stage: Deploy
  extends:
    - .python-tag
  script:
    - echo "Deployed!"

The Integrations stage has multiple jobs in it that take a decent chunk of time to run. It is unusual that all of the integration tests need to be run. This is why we stuck a manual flag on these, and the specific ones needed will be manually run.

How do I make it so that the Deploy stage requires that one or more of the jobs in Integration Tests has passed? I can either do all like I have now or I can do none by removing allow_failure: false from the integration test jobs.

I want to require that at least once has passed.

1 Answers

if each job generate an artifcact only when the job is successful

  artifacts:
    paths:
      - success.txt
  script:
    # generate the success.txt file

you should be able to test if the file exist in the next stage

you need to add this (below) in the next stage to be able to read the file:

  artifacts:
    paths:
      - success.txt
Related