我的GitLab管道有一些问题。
我想使用计划的规则来运行手动作业,或者找到一种方法来使用我的作业运行计划的管道而无需重写管道。
如示例所示,我有2个 firstjob 标记的工作。一种是手动的,另一种是预定的。我的问题是,如果我运行预定的工作流程,AC测试将不会启动,并且如果我尝试按预定的规则运行 FirstJob ,它将由于when: manual
部分而无法启动
这是我的例子:
stages:
- firstjob
- test
- build
- deploy
FirstJob:
stage: firstjob
script:
- echo "Hello Peoples!"
- sleep 1
when: manual
allow_failure: false
FirstJobSchedule:
stage: firstjob
script:
- echo "Hello Scheduled Peoples!"
- sleep 1
only:
- schedule
allow_failure: false
AC-test:
needs: [FirstJob]
stage: test
script:
- echo "AC Test is running"
- sleep 10
ProdJobBuild:
stage: build
needs: [AC-test]
script:
- echo "Building thing to prod"
ProdJobDeploy:
stage: deploy
needs: [ProdJobBuild]
script:
- echo "Deploying thing to prod"
答案 0 :(得分:0)
有一种方法可以使用only:
,但我建议移至rules:
,因为only:
将不推荐使用。
因此,您将不需要两个具有不同条件的作业,可以执行分支条件:
stages:
- firstjob
- test
- build
- deploy
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
FirstJob:
stage: firstjob
script:
- echo "Hello Peoples!"
- sleep 1
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
# when: always # is a default value
- when: manual
# allow_failure: false # is a default value
AC-test:
needs: [FirstJob]
stage: test
script:
- echo "AC Test is running"
- sleep 10
ProdJobBuild:
stage: build
needs: [AC-test]
script:
- echo "Building thing to prod"
使用它,管道可以检查作业是否被计划调用并运行。
如果没有,则停留在manual
。
*我可以自由选择MR-style of workflow来避免重复管道。