Steps

Updated 2 years ago by Admin

Pipeline steps are defined as a series of shell commands. The commands are executed inside the root directory of your git repository. The root of your git repository, also called the workspace, is shared by all steps in your pipeline.

Example configuration:

1  kind: pipeline
2 type: digitalocean
3 name: default
4
5 token:
6 from_secret: token
7
8 steps:
9 - name: backend
10 commands:
11 - go build
12 - go test
13
14 - name: frontend
15 commands:
16 - npm install
17 - npm test

Commands

The commands are executed inside the root directory of your git repository. The root of your git repository, also called the workspace, is shared by all steps in your pipeline. This allows file artifacts to persist between steps.

8  steps:
9 - name: backend
10 commands:
11 - go build
12 - go test

The above commands are converted to a simple shell script. The commands in the above example are roughly converted to the below script:

1  #!/bin/sh
2 set -e
3 set -x
4
5 go build
6 go test

The exit code is used to determine whether the step is passing or failing. If a command returns a non-zero exit code, the step is marked as failing. The overall pipeline status is also marked as failing, and remaining pipeline steps are skipped (unless explicitly configured to run on failure).


Environment

The environment section provides the ability to define environment variables scoped to individual pipeline steps.

8  steps:
9 - name: backend
10 environment:
11 GOOS: linux
12 GOARCH: amd64
13 commands:
14 - go build
15 - go test

Conditions

The when section provides the ability to conditionally limit the execution of steps at runtime. The below example limits step execution by branch, however, you can limit execution by event, reference, status and more.

8  steps:
8 - name: backend
10 commands:
11 - go build
12 - go test
13 when:
14 branch:
15 - master

Use the status condition to override the default runtime behavior and execute steps even when the pipeline status is failure:

8  steps:
9 - name: cleanup
10 commands:
11 - docker system prune -f
12 when:
13 status:
14 - failure
15 - success

See the Conditions article for additional details:


Failure

The failure attribute lets you customize how the system handles failure of an individual step. This can be useful if you want to allow a step to fail without failing the overall pipeline.

8  steps:
9 - name: backend
10 failure: ignore
11 commands:
12 - go build
13 - go test


How did we do?