Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering a pipeline and waiting for it to finish from another pipeline

I have two different project repositories: my application repository, and an API repository. My application communicates with the API.

I want to set up some integration and E2E tests of my application. The application will need to use the latest version of the API project when running these tests.

The API project is already setup to deploy when triggered

deploy_integration_tests:
  stage: deploy
  script:
  - echo "deploying..."
  environment:
    name: integration_testing
  only:
    - triggers

My application has an integration testing job set up like this:

integration_test
  stage: integration_test
  script:
    - echo "Building and deploying API..."
    - curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>
    - echo "Now running the integration test that depends on the API deployment..."

The problem I am having is that the trigger only queues the API pipeline (both projects are using the same runner) and continues before the API pipeline has actually run.

Is there a way to wait for the API pipeline to run before trying to run the integration test?

I can do something like this:

integration_test_dependency
  stage: integration_test_dependency
  script:
    - echo "Building and deploying API..."
    - curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>

integration_test
  stage: integration_test
  script:
    - echo "Now running the integration test that depends on the API deployment..."

But that still doesn't grantee that the API pipeline runs and finishes before moving on to the integration_test stage.

Is there a way to do this?

like image 678
dseiple Avatar asked Jun 02 '17 19:06

dseiple


2 Answers

I've come across this limitation recently and have set up an image that can be re-used to make this a simple build step:

https://gitlab.com/finestructure/pipeline-trigger

So in your case this would look like this using my image:

integration_test
  stage: integration_test
  image: registry.gitlab.com/finestructure/pipeline-trigger
  script:
    - echo "Now running the integration test that depends on the API deployment..."
    - trigger -a <api token> -p <token> <project id>

Just use the project id (instead of having to find the whole url) and create a personal access token, which you supply here (best do this via a secret).

The reason the latter is needed is for polling the pipeline status. You can trigger without it but getting the result needs API authorisation.

See the project description for more details and additional things pipeline-trigger can do.

like image 116
sas Avatar answered Oct 22 '22 12:10

sas


In case anyone else is here looking for this on triggered pipelines from the ci yaml, you can use the keyword depend for strategy to ensure the pipeline waits for the triggered pipeline:

    trigger: 
      project: group/triggered-repo
      strategy: depend
like image 37
enderland Avatar answered Oct 22 '22 12:10

enderland