How to setup parallel Pipeline steps (1.0+)


#1

Pipeline steps are executed sequentially by default. You can optionally use the depends_on keywork to describe your build steps as a directed acyclic graph. In the below example, steps foo and bar execute in parallel, and baz executes once both steps complete.

kind: pipeline
name: foo

steps:
- name: foo
  image: golang
  commands:
  - go build
  - go test

- name: bar
  image: node
  commands:
  - npm install
  - npm test

- name: baz
  image: plugins/slack
  settings:
    webhook:
      from_secret: webhook
  depends_on:
  - foo
  - bar

The above example is quite simple, but you could use this syntax to create very complex execution flows. The below diagram provides a visual representation of what a complex graph execution could look like:

Topological_Ordering


#2

If you were using the group keyword in previous versions of Drone, you should be able to emulate the same behavior with depends_on.

Example 0.8 yaml configuration using groups:

pipeline:
  step1a:
    image: alpine
    group: group1
  step1b:
    image: alpine
    group: group1

  step2a:
    image: alpine
    group: group2
  step2b:
    image: alpine
    group: group2

  step3:
    image: alpine
    # no group

The above configuration file can be represented in 1.0 using the following syntax:

kind: pipeline

steps:
- name: step1a
  image: alpine
- name: step1b
  image: alpine

- name: step2a
  image: alpine
  depends_on: [ step1a, step1b ]
- name: step2b
  image: alpine
  depends_on: [ step1a, step1b ]

- name: step3
  image: alpine
  depends_on: [ step2a, step2b ]

#3

It seems like depends_on on 3rd task implicitly declares tasks 1 and 2 to be executed in parallel. Am I right? This implicitness is very confusing IMO.


#4

if I want let all step run at the same time , I have to create a useless step with a depends_on include a step name. it don’t seem good , any others better resolve way ?


#5

@shynome

steps:
- name: one
 image: alpine
 depends_on: [ clone ]
- name: two
 image: alpine
 depends_on: [ clone ]
- name: three
 image: alpine
 depends_on: [ clone ] 

#6

Thank you, it’s helpful


#8

See https://docs.drone.io/user-guide/pipeline/multi-machine/


#9

Oh sorry! I’ve just read that too!