Pipeline

The pipeline section defines a list of steps that allow you to build, test and deploy your code. Pipeline steps are (by default) executed sequentially, in the order in which they are defined. If a step returns a non-zero exit code, the pipeline immediately aborts and returns a failure status.

Example pipeline:

pipeline:
  backend:
    image: golang
    commands:
      - go build
      - go test
  frontend:
    image: node
    commands:
      - npm install
      - npm run test
      - npm run build

In the above example we define two pipeline steps, frontend and backend. The names of these steps are completely arbitrary.

Build Steps

Build steps are steps in your pipeline that execute commands inside a specified Kubernetes Pod. These commands are executed using a workspace as their working directory.

pipeline:
  backend:
    image: golang
    commands:
+     - go build
+     - go test

There's no magic, here; the above commands are roughly converted to the simple shell script, below:

#!/bin/sh
set -e

go build
go test

The above shell script is then executed as a container command. The below kubectl command is an (incomplete) example of how that execution takes place:

kubectl run backend --image=golang --command -- build.sh

Please note that only build steps can define commands. You cannot use commands with plugins or services.

Parallel Execution

The Pipeline CI/CD supports parallel step execution to achieve fan-in and fan-out on a single node. Parallel steps are configured using the group attribute, which instructs the pipeline runner to execute that designated group in parallel.

Here's an example parallel configuration:

pipeline:
  backend:
+   group: build
    image: golang
    commands:
      - go build
      - go test
  frontend:
+   group: build
    image: node
    commands:
      - npm install
      - npm run test
      - npm run build
  publish:
    image: plugins/docker
    repo: octocat/hello-world

In the above example, the frontend and backend steps are executed in parallel. The pipeline runner will not execute the publish step until the group is completed.

Conditional Pipeline Execution

The Pipeline CI/CD gives you the ability to skip commits based on the target branch. The below example skips a commit whenever its target branch is not master.

pipeline:
  build:
    image: golang
    commands:
      - go build
      - go test

+branches: master

Please see the pipeline conditions documentation for more options and details.

Conditional Step Execution

Pipeline's CI/CD gives us the ability to conditionally limit the execution of steps at runtime. The example below limits execution of Slack plugin steps based on the branch:

pipeline:
  slack:
    image: plugins/slack
    channel: dev
+   when:
+     branch: master

Please see the step conditions documentation for more options and details.

Failure Execution

Pipeline CI/CD uses the Pod's exit code to determine the success or failure status of a build. Non-zero exit codes fail the build and cause the pipeline to immediately exit.

There are use cases for executing pipeline steps on failure, such as sending notifications for failed builds. Use the status constraint to override default behavior, and execute steps even when the status of the build is failure:

pipeline:
  slack:
    image: plugins/slack
    channel: dev
+   when:
+     status: [ success, failure ]

Please see the step conditions documentation for more options and details.