Home > Enterprise >  gitlab-ci.yml: jobs dependencies
gitlab-ci.yml: jobs dependencies

Time:02-02

Imagine there are stages:

stages:
    - test
    - build
    - deploy

And one need to split test stage into smaller jobs like build-test-image, pytest, run-linters, etc. Jobs run-tests, run-linters can be run only when build-test-image worked.

I tried this but it's not working:

build-test-image:
  stage: test
  image: ${DOCKER_REGISTRY}/docker:stable
  script:
      - docker build -t ${TEST_CONTAINER_REF} --build-arg ENV=test ./backend
  artifacts:
    when: always
  only:
    - merge_requests

pytest:
  stage: test
  image: ${DOCKER_REGISTRY}/docker:stable
  script:
      - docker run --name ${TEST_CONTAINER_REF} -e SECRET_KEY=${TEST_SECRET_KEY} ${TEST_CONTAINER_REF} runtests; exit $?
  after_script:
      - docker rm ${TEST_CONTAINER_REF}
  only:
    - merge_requests
  needs:
    - build-test-image

Error:

enter image description here

CodePudding user response:

In principle, if a job declares a needs statement then this job,in order to execute, it has to wait for the jobs that were referred in the statement to finish, even if they are in the same stage

In your case run-tests should wait for the build-test-image.

If you are on a self hosted check your Gitlab version

https://your.domain.com/help

The functionality you need was added in 14.2enter image description here

  •  Tags:  
  • Related