限制 gitlab-ci 中的分叉项目(使用自动开发)

Restrict phase forked projects in gitlab-ci (with auto devops)

需要限制阶段,例如仅部署到主项目。但是,构建和测试需要适用于所有分叉项目。

我已将阶段:部署限制在 "master" 上。然而,这限制了构建不能只在 feature master 上执行,还要在 "forked" projects master 上执行。


variables:
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"
  MAVEN_OPTS: "-Djava.awt.headless=true -Dmaven.repo.local=./.m2/repository"

cache:
  paths:
    - ./.m2/repository
  # keep cache across branch
  key: "$CI_BUILD_REF_NAME"


stages:
  - build
  - test
  - deploy

build:
  stage: build
  cache:
    key: edu-erp
    paths:
      - .m2/repository/
  script:
    - "mvn clean compile $MAVEN_CLI_OPTS"
  artifacts:
    paths:
      - target/

test:
  stage: test
  cache:
    key: edu-erp
  script:
    - "mvn test $MAVEN_CLI_OPTS"

deploy_review:
  stage: deploy
  script:
    - echo "deploy_review"
  only:
    - branches
  except:
    - master
  when:
    manual

deploy_staging:
  stage: deploy
  script:
    - echo "deploy_staging"
  only:
    - master

deploy_prod:
  stage: deploy
  script:
    - echo "Deploy to prod"
  only:
    - master
  when:
    manual

场景是gitlab上有个开源项目。每个人都分叉项目;但是分叉的项目不应该部署工件。

您可以使用 only 键值中的 @ 语法解决此问题(reference,向下滚动)。

鉴于您的小组和项目名为 mygroupmyproject,它看起来像这样:

deploy_prod:
  stage: deploy
  script:
    - echo "Deploy to prod"
  only:
    - master@gitlab-org/gitlab-ce
  when:
    manual