Orchestrate Jobs#
作为 CI/CD 工具, 编排任务是最重要的功能之一. 常见的编排有顺序执行, 并行执行. 当某个 job 是否直接退出还是仅仅报错并继续执行. 对于并行执行的 job 是不是可以有个允许百分之多少的 job 失败. 哪些 job 必须等待其他 job 完成后才能执行. 这些都是编排任务的一部分.
Sample Workflow Definition#
1# demonstrate how to orchestrate jobs
2name: 01_03_orchestrate_jobs
3on:
4 workflow_dispatch:
5# A workflow run is made up of one or more jobs that can run sequentially or in parallel
6#
7# - Defining prerequisite jobs: https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow#defining-prerequisite-jobs
8# - jobs.<job_id>.needs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds
9jobs:
10 # the DAG diagram looks like:
11 # build -> [test1, test2] -> deploy
12 build:
13 runs-on: ubuntu-latest
14 steps:
15 - name: build
16 run: echo building
17 test1:
18 needs: [build]
19 runs-on: ubuntu-latest
20 steps:
21 - name: test1
22 run: echo testing
23 test2:
24 needs: [build]
25 runs-on: ubuntu-latest
26 steps:
27 - name: test2
28 run: echo testing
29 deploy:
30 needs: [test1, test2]
31 runs-on: ubuntu-latest
32 steps:
33 - name: deploy
34 run: echo deploying