如何为 gitlab ci/cd 作业添加依赖?

问题描述 投票:0回答:1

仅当 test-job1 成功时,我才想执行 test-job2 。我如何配置,以便 test-job2 在 test-job1 完成并成功后立即被解雇。

build-job:
  stage: build
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"

test-job1:
  stage: test
  script:
    - python3 mydumbscript.py $arg1 $arg2 $arg3


test-job2:
  stage: test
  script:
    - echo "This job tests something, but takes more time than test-job1."
    - echo "After the echo commands complete, it runs the sleep command for 20 seconds"
    - echo "which simulates a test that runs 20 seconds longer than test-job1"
    - sleep 20

gitlab-ci
1个回答
0
投票

您可以使用

jobs.<job_id>.needs
来设置依赖关系。

例如,在下面,

job2
等待
job1
成功完成才开始。

jobs:
  job1:
  job2:
    needs: job1
  job3:
    needs: [job1, job2]

就您而言,我想您需要在

needs: test-job1
下添加
test-job2

© www.soinside.com 2019 - 2024. All rights reserved.