In GitLab's CI/CD system how do I prevent a job from running if it's in my fork and only allow it to run if its a merge to the main repo?

杀马特。学长 韩版系。学妹 提交于 2020-12-06 12:52:09

问题


I have a job in my gitlab-ci.yml like

build and push:
  stage: push
  only:
  - master
  script:
  - gcloud docker -- push $IMAGE_TAG

The idea being that it should only run if the branch is master, but I also only want it to run if the repo is app/ and not dave/

The docs say

The repository path can be used to have jobs executed only for the parent repository and not forks:

job:
  only:
    - branches@gitlab-org/gitlab-ce

but I can't get this to work. If our gitlab server is gitlab.myco.io and the app is app/my-project-name I figured I could put

job:
  only:
    - branches@gitlab-myco-io/app/my-project-name/master

but that does not seem to work.

What is the correct way to do this?


回答1:


Try changing it to configuration below. You don't need it to run for all branches (only master branch) and that too of the original repo.

job:
  only:
    - master@app/my-project-name


来源:https://stackoverflow.com/questions/56070922/in-gitlabs-ci-cd-system-how-do-i-prevent-a-job-from-running-if-its-in-my-fork

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!