当.gitlab-ci.yml仅在合并请求中运行时,如何正确写入作业?
test_c:
stage: test
script:
- echo "This job tests something. It will only run when all jobs in the"
- echo "build stage are complete."
only:
- merge_requests此作业未在合并请求中运行,但未在master或develop中的commint中运行。
发布于 2020-09-15 09:35:29
Gitlab文档建议使用'rules‘而不是'only’。您可以通过执行以下操作来仅完成merge_requests:
test_c:
stage: test
script:
- echo "This job tests something. It will only run when all jobs in the"
- echo "build stage are complete."
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'发布于 2021-10-13 07:59:20
您可以使用workflow来控制管道的创建。使用单个rules在顶层定义此关键字。此示例显示,只有在创建新的合并请求时才会执行管道,最后一个when被设置为never,以防止在将新分支推送到服务器或任何其他类型的事件时执行管道。
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
when: always
- when: never请注意Gitlab documentation中提到的
这些管道在UI中被标记为已分离,并且它们没有访问受保护变量的权限。否则,这些管道与其他管道相同。
发布于 2020-05-19 20:34:06
您的代码是正确的,请在测试您的merge_request管道之前将其提交给master。
https://stackoverflow.com/questions/61878576
复制相似问题