Post-Step Operations

Annotate your builds and run extra steps

Post-step operations are a set of optional predefined processes that can be configured on any step. These operations will be executed once the step has completed. The post-step operations allow you to annotate your builds, images and pipelines with extra metadata or run other steps.

Result Aware Post-Step Operations

You may execute post-step operations conditionally, based on the outcome of the step itself.

To execute operations only when the step has completed successfully, use on_success:

step_name:
  ...
  on_success:
    ...

To execute operations only when the step has failed, use on_fail:

step_name:
  ...
  on_fail:
    ...

Result Agnostic Post-Step Operations

You may execute post-step operations regardless of the outcome of the step itself.

To execute operations regardless of the result, use on_finish:

step_name:
  ...
  on_finish:
    ...

Available Post-Step Operations

Example

Marking a Docker image with the results of unit tests:

build_step:
  title: Building My Docker image
  type: build
  image_name: my-app-image
  tag: 1.0.1
  dockerfile: Dockerfile
run_tests:
  title: Running unit tests
  image: ${{build_step}}
  commands:
   - npm install
   - npm run test
  on_success: # Execute only once the step succeeded
    metadata: 
      set: 
        - ${{build_step.imageId}}: 
          - unit_tests: passed

Running other steps

If you want to run another step in the pipeline when another step fails or succeeds you need to use conditional execution of steps and the fail_fast property. You can also use step hooks for dedicated post step actions.

run_tests:
  title: Running unit tests
  image: node:11
  fail_fast: false
  commands:
   - npm install
   - npm run test
print_error_message:
  image: alpine:latest
  title: Marking pipeline status
  commands:
  - echo "Unit tests failed"
  when:
    condition:
      all:
        myCondition: run_tests.result == 'failure'

In this example the step print_error_message will only run if step run_tests has failed.

See also advanced workflows and Pipeline/Step hooks.