How to make a stage depend on another stage?

Viewed 2207

I have a YAML file as below. Let’s say the *.md file is committed, the build does not work, but the test works. Here how can I make the test depend on the build? Like if the build doesn’t work, the test shouldn’t work.

Thanks in advance.

build:
  stage: build
  script:
    - echo "Build is running"
  only:
    changes:
      - Dockerfile
      - requirements.txt
      - ./configs/*
test:
  stage: test
  script:
    - echo "Test is running"
    - echo "$CI_JOB_STAGE"
  dependencies:
   - build
1 Answers

That should be what stages defines

Use stages to define stages that contain groups of jobs.
stages is defined globally for the pipeline.
Use stage in a job to define which stage the job is part of.

The order of the stages items defines the execution order for jobs:

  • Jobs in the same stage run in parallel.
  • Jobs in the next stage run after the jobs from the previous stage complete successfully.

For example:

stages:
 - build
 - test
 - deploy
  • All jobs in build execute in parallel.
  • If all jobs in build succeed, the test jobs execute in parallel.
  • If all jobs in test succeed, the deploy jobs execute in parallel.
  • If all jobs in deploy succeed, the pipeline is marked as passed.

If any job fails, the pipeline is marked as failed and jobs in later stages do not start.
Jobs in the current stage are not stopped and continue to run.

So, in your case:

stages:
  - build
  - test

test won't run if build fails.

Related