1
votes

My .gitlab-ci.yml looks like below. Since docker-build stage will run if branch is master and deploy-dev depends on docker-build stage. deploy-dev stage is showing up even the branch is not master but a feature branch I dont want deploy-dev stage to show up either. It does not make sense, and can cause problem. How can I achieve this? Thanks

docker-build:
  image: docker:19.03.12
  stage: docker-build
  services:
    - docker:19.03.12-dind
  script:
    - docker build -t .....
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master"'

deploy-dev:
  stage: deploy
  image: microsoft/azure-cli
  dependencies:
    - docker-build
  script:
    - ......
  when:
    manual
1
When do you want to see deploy-dev ? Only on master ? - Nicolas Pepinster
Yes, when it is only master. But it also does not make sense since it says it depends on docker-build - user14571611
Unfortunately, except by adding the same rule as for docker-build, that's not possible. - Nicolas Pepinster
Thanks Nicolas. - user14571611

1 Answers

0
votes

The dependencies keyword is a bit of a misnomer. It doesn't control which other jobs a job depends on, but rather which artifacts a job depends on. If a job doesn't have the dependencies keyword, it will download all artifacts from previous jobs. If it's an empty array, ([]) it won't download any artifacts.

Currently, there is no way other than the only/except or rules keywords to restrict which jobs run in a pipeline.