我有一个gitlab管道,其中有两个阶段,一个阶段是构建,另一阶段是部署。进行提交时将运行构建阶段。我希望有一种在合并请求合并到主服务器时运行部署作业的方法。我尝试了几件事,但是没有运气。有人可以帮忙吗?
stages:
- build
- deploy
dotnet:
script: "echo This builds!"
stage: build
production:
script: "echo This deploys!"
stage: deploy
only:
refs:
- master
答案 0 :(得分:4)
尝试使用gitlab-ci.yml“规则”功能检查合并请求事件。
您当前的gitlab-ci.yml将在每次提交,合并请求,计划和手动触发的管道时运行“ dotnet”作业。
https://docs.gitlab.com/ee/ci/yaml/#workflowrules
dotnet:
script: "echo This builds!"
stage: build
rules:
- if: '$CI_BUILD_REF_NAME != "master" && $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"'
production:
script: "echo This deploys!"
stage: deploy
rules:
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_BUILD_REF_NAME == "master"'