Run autotests pipeline by docker image, which built at parent pipeline

20 Views Asked by At

I have different gitlab repositories for development and autotests, so I have different gitlab pipelines for developments and autotests. Now development pipeline run after merge code to master branch. This pipeline build and push docker image to storage and after run pipeline with running tests. Now I overwrite image every time. I want to make pipeline, which run before merge development code to master branch. This pipeline should build docker image and run pipeline with test by this image. But I don't know, how I can transfer to tests pipeline docker images, which built at parent pipeline?

1

There are 1 best solutions below

0
sytech On

In your upstream pipeline that builds the image, you can do something like this:

  1. Build your image, tag it with $CI_PIPELINE_ID (you could also use something else like CI_COMMIT_SHA or similar) and push it to your registry
  2. Trigger the downstream project pipeline, passing the tag as a variable

In the downstream project:

  1. Use the variable to pull the image
  2. Test it

So, your upstream CI configuration, may have something like this:

build:
  script:
    - docker build -t $MY_REGISTRY/$MY_IMAGE:$CI_PIPELINE_ID .
    - docker push $MY_REGISTRY/$MY_IMAGE:$CI_PIPELINE_ID 

trigger_tests:
  needs: [build]
  trigger: path/to/my-testing-project
  variables:
    UPSTREAM_TAG: $CI_PIPELINE_ID
  strategy: depend

Then in the downstream testing project CI configuration:

test_upstream:
  script:
    - docker pull $MY_REGISTRY/$MY_IMAGE:$UPSTREAM_TAG
    - make test

See: Downstream pipelines for more information