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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With