0
votes

I have 2 Gitlab repos:

  1. Project A
  2. Integration tests for Project A

I want to stop the pipeline / build of Project A if the integration tests fail but currently the Project A pipeline passes even if the integration tests fail.

My .gitlab-ci.yml for Project A defines these 7 stages:

stages:
  - build
  - test
  - publish
  - dev-deployment
  - staging-deployment
  - trigger-integration-tests
  - prod-deployment

The second last stage (trigger-integration-tests) kicks off the integration tests project by using the Gitlab API call with curl:

trigger-integration-tests:
  stage: trigger-integration-tests
  image: ubuntu:16.04
  script:
  - apt-get update && apt-get install -y curl
  - "curl -X POST -F token=$INTEGRATION_TESTS_TOKEN -F variables[PROJECT_ID]=$CI_PROJECT_ID -F variables[BRANCH_NAME]=$CI_COMMIT_REF_NAME -F ref=master https://gitlab.mycompany.com/api/v4/projects/123/trigger/pipeline"
  allow_failure: false
  only:
  - master

I tried adding the allow_failure: false flag but that didn't help so I'm looking for more ideas.

I found the trigger-and-wait technique but wasn't sure if there's a more simple solution.

1

1 Answers

1
votes

As answered on a previous question, you could do the following:

From the main project, using a Python/Bash script:

  1. Trigger the integration tests pipeline (and capture the pipeline ID)
  2. Poll the status of the pipeline, using the captured ID (which can be running, pending, failed, canceled or skipped)
  3. Raise an exception / error if it has failed...

See here for an example python script to achieve this.