Use the needs syntax in pipeline YAML to control the execution order of jobs.
-
In Alibaba Cloud DevOps, use the
stages.<stage_id>.jobs.<job_id>.needssyntax in a pipeline YAML file to define job dependencies. -
For example, suppose you need to build and deploy app1 and app2 together. The build job for app1 depends on both its unit testing and code scanning jobs, and so does app2. The build jobs for app1 and app2 can run in parallel, but the deployment of app2 depends on the app1 deployment.
-
The following YAML example shows this setup:
sources: my_repo1: type: gitSample name: app1 code source endpoint: https://atomgit.com/flow-example/spring-boot.git branch: master my_repo2: type: gitSample name: app2 code source endpoint: https://atomgit.com/flow-example/node-expressjs.git branch: master defaultWorkspace: my_repo1 stages: build_stage: name: Build jobs: test_job1: name: app1 unit testing steps: command_step: name: Execute Command step: Command with: run: | echo This is build job... scan_job1: name: app1 code scanning steps: command_step: name: Execute Command step: Command with: run: | echo This is build job... test_job2: name: app2 unit testing steps: command_step: name: Execute Command step: Command with: run: | echo This is build job... scan_job2: name: app2 code scanning steps: command_step: name: Execute Command step: Command with: run: | echo This is build job... build_job1: name: app1 build # This job depends on test_job1 and scan_job1. needs: - test_job1 - scan_job1 steps: command_step: name: Execute Command step: Command with: run: | echo This is build job... build_job2: name: app2 build # This job depends on test_job2 and scan_job2. needs: - test_job2 - scan_job2 steps: command_step: name: Execute Command step: Command with: run: | echo This is build job... deploy_stage: name: Deployment jobs: deploy_job1: name: app1 deployment steps: command_step: name: Execute Command step: Command with: run: echo This is deploy env 1... deploy_job2: name: app2 deployment # This job depends on deploy_job1. needs: deploy_job1 steps: command_step: name: Execute Command step: Command with: run: echo This is deploy env 2...