Pipelines
Call a pipeline (reusable pipelines)
Write jobs once in a pipeline file with on: call, and use them as one job of another pipeline.
Available in repositories branchd reads pipeline files for. It is switching repositories on one at a time: until yours is, it keeps running its
.forge-ci.yamlor.xeonr-ci.yaml. See What is available.
The reusable pipeline:
# .branchd/pipelines/deploy.yaml
# A reusable pipeline: on: call only, so it never runs on its own. A job
# that uses it gets its two jobs, named "<calling job> / plan" and
# "<calling job> / apply".
on:
call:
inputs:
version: {type: string, required: true}
environment: {type: choice, options: [stage, production], default: stage}
secrets:
DEPLOY_TOKEN: {required: true}
outputs:
revision: ${{ jobs.apply.outputs.revision }}
env:
TARGET: ${{ inputs.environment }}
jobs:
plan:
image: alpine:3
steps:
- run: ./scripts/plan.sh "${{ inputs.version }}" "$TARGET"
apply:
needs: [plan]
image: alpine:3
secrets: [DEPLOY_TOKEN]
outputs:
revision: ${{ steps.apply.outputs.revision }}
steps:
- id: apply
run: ./scripts/apply.sh "${{ inputs.version }}" "$TARGET" >> "$BRANCHD_OUTPUT"
The pipeline that calls it, twice:
# .branchd/pipelines/ci.yaml
# Calls deploy.yaml twice, once per environment. The run's jobs are build,
# stage / plan, stage / apply, production / plan, production / apply and
# announce.
name: CI
on:
push:
branches: [main]
jobs:
build:
image: alpine:3
outputs:
version: ${{ steps.v.outputs.version }}
steps:
- id: v
run: echo "version=1.0.$CI_PIPELINE_IID" >> "$BRANCHD_OUTPUT"
stage:
needs: [build]
uses: ./.branchd/pipelines/deploy.yaml
with:
version: ${{ needs.build.outputs.version }}
environment: stage
secrets: [DEPLOY_TOKEN]
production:
needs: [build, stage]
uses: ./.branchd/pipelines/deploy.yaml
with:
version: ${{ needs.build.outputs.version }}
environment: production
secrets: [DEPLOY_TOKEN]
environment: production
manual: true
announce:
needs: [production]
image: alpine:3
steps:
- run: echo "deployed ${{ needs.production.outputs.revision }}"
on: callmakes a file callable. It declaresinputs(typed as for manual runs),secrets({required, description}) andoutputs, each output one job's output,${{ jobs.<id>.outputs.<name> }}. A file that declares onlyon: callnever runs on its own.- A calling job has
uses:instead ofsteps::./<path>.yamlfrom the repository's root, at this commit, or another repository's pipeline,<group>/<repo>/<path>.yaml@v1(see Other repositories). Its called jobs join this run, named<calling job> / <job>, with checks such asCI / stage / apply. - The calling job takes
uses,with,needs,if,secrets,allow,runs-on,environment,concurrency,manualandmatrix. It runs nothing itself. matrix:on the calling job calls the pipeline once per cell, as GitHub calls a reusable workflow from a matrix: the cell's jobs are<calling job> (<values>) / <job>, itswith:andif:read${{ matrix.<key> }}, and a job that needs the calling job waits for every cell's jobs. A matrix call has no outputs. With two or more cells, a failed called job cancels unfinished jobs across the call unless its matrix setsfail-fast: false.with:gives the inputs. A whole${{ needs.<job>.outputs.<name> }}of a job it needs passes that output to astringorchoiceinput.secrets:lists what it passes. Each must be declared underon.call.secrets; a required one must be passed. A called job gets, of the secrets in its ownsecrets:, those the caller passed.needs:on the calling job is what the called pipeline's first jobs wait for. A job that needs the calling job needs all its jobs, and reads the declared outputs as${{ needs.<calling job>.outputs.<name> }}.environment:,concurrency:andmanual:on the calling job are set on every called job.manual: trueabove makesproduction / planandproduction / applyeach wait to be released. A called job that sets its ownenvironmentorconcurrencyas well is refused.- What a called pipeline reads: the run's facts, its inputs, its own
env:and its own jobs. The repository's settings variables (vars) are refused there: pass them as inputs. - Its jobs run as the calling repository, with its job token (at most the
calling job's
permissions:), runners and the secrets passed. A secreton.call.secretsdeclaresrequired: falsemay be left out. A pipeline has at most 500 jobs, called jobs and matrix cells included.