Hank Chow
Hank Chow

Reputation: 564

How to get the results (succeeded or failed) of previous stages/jobs in a pipeline of GitLab CI?

In one pipeline there are multiple stages. How can I get the results (succeeded or failed) of previous stages/jobs in the last stage/job of a pipeline?

Upvotes: 4

Views: 8791

Answers (2)

kwick
kwick

Reputation: 787

You can use "artifacts:reports:dotenv" feature

Check out below code:

---
build:
  stage: build
  script:
    - VAR1=foo
    - VAR2=bar
    - echo VAR1="${VAR1}" > $CI_PROJECT_DIR/variables.env
    - echo VAR2="${VAR2}" >> $CI_PROJECT_DIR/variables.env
  artifacts:
    reports:
      dotenv: variables.env

test:
  stage: test
  script:
    - echo VAR1 is $VAR1
    - echo VAR2 is $VAR2

This was a famous ask from many people to GitLab, check out here, above code is taken from this discussion only.

Upvotes: 2

Kaish kugashia
Kaish kugashia

Reputation: 254

One way is to use the gitlab-ci job api to find the status from its response; However, depending on your use case; you can also use CI_JOB_STATUS in the 'after_script` of the same job.

You can use a custom variable as a flag, that you can set in the after script of the same job based on CI_JOB_STATUS.

Note: CI_JOB_STATUS can be success, failed, or canceled

Upvotes: 4

Related Questions