Steps
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: kubernetes
3 name: default
4
5 steps:
6 - name: backend
7 image: golang
8 commands:
9 - go build
10 - go test
11
12 - name: frontend
13 image: node
14 commands:
15 - npm install
16 - 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.
5 steps:
6 - name: backend
7 image: golang
8 commands:
9 - go build
10 - 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 above shell script is then executed as the docker entrypoint. The below docker command is an (incomplete) example of how the script is executed:
docker run --entrypoint=build.sh golang
The container 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.
5 steps:
6 - name: backend
7 image: golang
8 environment:
9 GOOS: linux
10 GOARCH: amd64
11 commands:
12 - go build
13 - go test
Plugins
Plugins are docker containers that encapsulate commands, and can be shared and re-used in your pipeline. Examples of plugins include sending Slack notifications, building and publishing Docker images, and uploading artifacts to S3.
Example Slack plugin:
15 - name: notify
16 image: plugins/slack
17 settings:
18 webhook: https://hooks.slack.com/services/...
The great thing about plugins is they are just Docker containers. This means you can easily encapsulate logic, bundle in a Docker container, and share your plugin with your organization or with the broader community.
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.
5 steps:
6 - name: backend
7 image: golang
8 commands:
9 - go build
10 - go test
11 when:
12 branch:
13 - master
Use the status condition to override the default runtime behavior and execute steps even when the pipeline status is failure:
15 - name: notify
16 image: plugins/slack
17 settings:
18 webhook: https://hooks.slack.com/services/...
19 when:
20 status:
21 - failure
22 - 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.
5 steps:
6 - name: backend
7 image: golang
8 failure: ignore
9 commands:
10 - go build
11 - go test
Detach
The detach attribute lets execute the pipeline step in the background. The runner starts the step, detaches and runs in the background, and immediately proceeds to the next step.
The target use case for this feature is to start a service or daemon, and then execute unit tests against the service in subsequent steps.
5 steps:
6 - name: backend
7 image: golang
8 detach: true
9 commands:
10 - go build
11 - go test
12 - go run main.go -http=:3000
Privileged Mode
The privileged attribute runs the container with escalated privileges. This is the equivalent of running a container with the --privileged
flag.
5 steps:
6 - name: backend
7 image: golang
8 privileged: true
9 commands:
10 - go build
11 - go test
12 - go run main.go -http=:3000
Resources
The resources section is used to request and limit CPU and memory resources for an individual pipeline step. See the Kubernetes documentation to learn more about managing compute resources.
5 steps:
6 - name: backend
7 image: golang
8 resources:
9 requests:
10 cpu: 250
12 memory: 250MiB
13 limits:
14 cpu: 500
15 memory: 500MiB
16 commands:
17 - go build
18 - go test
19 - go run main.go -http=:3000