Pipelines
Pass outputs between steps and jobs
Write a value in one step and read it in a later step of the same job, or in a job that needs this one.
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.
# .branchd/pipelines/ci.yaml
# A step writes name=value lines to $BRANCHD_OUTPUT. A later step of the
# same job reads them as steps.<id>.outputs.<name>; a job that needs this
# one reads the job's outputs as needs.<job>.outputs.<name>.
name: CI
on: push
jobs:
version:
image: alpine:3
outputs:
version: ${{ steps.v.outputs.version }}
channel: ${{ steps.v.outputs.channel }}
steps:
- id: v
run: |
echo "version=1.4.$CI_PIPELINE_IID" >> "$BRANCHD_OUTPUT"
echo "channel=${{ branch == 'main' && 'stable' || 'beta' }}" >> "$BRANCHD_OUTPUT"
- name: Use it in the same job
run: echo "building ${{ steps.v.outputs.version }}"
package:
needs: [version]
image: alpine:3
env:
VERSION: ${{ needs.version.outputs.version }}
steps:
- run: echo "packaging $VERSION for ${{ needs.version.outputs.channel }}"
- Writing. A step writes
name=valuelines to the file named by$BRANCHD_OUTPUT. Each step gets a fresh one. - In the same job. A step with an
id:makes its outputs readable by later steps as${{ steps.<id>.outputs.<name> }}. - To other jobs. The job's
outputs:map names to values, usually a step's output. A job that needs it reads${{ needs.<job>.outputs.<name> }}inrun:,env:,with:andimage:. - One line each. An output is one line; a value whose fixed text has a line break is refused.
- Known only while the job runs. A job that reads another's outputs must
need it, directly. An
if:may read them: a step'sif:reads an earlier step's (if: steps.changes.outputs.api == 'true'), decided when the step's turn comes, and a job'sif:reads a needed job's (if: needs.release.outputs.released == 'true'), decided when its needs have run; a job whoseif:is then false is skipped, with the jobs that need it. Only==,!=,contains,startsWith,endsWith, an output on its own (true when not empty),!,&&and||read an output in anif:; an output never set reads as''. See Expressions. - Names. Two step ids, job ids or output names that differ only in
-and_are refused: they would name the same variable. - Where they reach. A
run:job's outputs reach therun:steps andenv:of the jobs that need it. To feed a typed step'swith:or a job'simage:, the value must come from a typed step's job, as in Build and push an image. - A matrix job has no outputs.
Not yet available (script outputs to images): a
run:job's outputs reaching another job'simage:or a typed step'swith:. Only a typed step's outputs reach those.