跳到主要内容

Passing Output Parameters Between Tasks

Applicable Scenario: When you need to pass output parameters between steps, jobs, or even workflows, for example, passing the build version number from a build job to a deploy job.

Prerequisites

  • Understand the roles of id, outputs, and needs.
  • Understand how to use the ATOMGIT_OUTPUT environment variable.

Quick Example

name: pipeline-with-outputs

on:
push:
branches:
- main

jobs:
prepare:
runs-on: [ubuntu-latest, x64, small]
steps:
- id: version
run: echo "version=1.0.0" >> "$ATOMGIT_OUTPUT"
- id: sha
run: echo "sha=${{ atomgit.sha }}" >> "$ATOMGIT_OUTPUT"

build:
runs-on: [ubuntu-latest, x64, small]
needs: prepare
steps:
- name: Use output from prepare
run: |
echo "version=${{ jobs.prepare.outputs.version }}"
echo "sha=${{ jobs.prepare.outputs.sha }}"

Configuration Description

Three-Level Transmission Model

AtomGit Action supports three-level transmission of outputs: Step → Job → Workflow

Step Output (ATOMGIT_OUTPUT)
→ Mapped to Job Output (jobs.<job_id>.outputs)
→ Mapped to Workflow_call Job Output (jobs.workflow_call_job_id.outputs)

Step Output

Write outputs in a step using the ATOMGIT_OUTPUT environment variable:

steps:
- id: version
run: echo "version=1.0.0" >> "$ATOMGIT_OUTPUT"

- id: build-result
run: |
echo "status=success" >> "$ATOMGIT_OUTPUT"
echo "artifact-path=dist/app.tar.gz" >> "$ATOMGIT_OUTPUT"

- name: Use step output
run: echo "version=${{ steps.version.outputs.version }}"

Note: The value of each output parameter cannot exceed 1MB. Use delimiter syntax for multi-line outputs.

Job Output

Map step outputs to job outputs so that other jobs can reference them via needs:

jobs:
prepare:
runs-on: [ubuntu-latest, x64, small]
steps:
- id: version
run: echo "version=1.0.0" >> "$ATOMGIT_OUTPUT"
- id: build-result
run: echo "status=success" >> "$ATOMGIT_OUTPUT"

deploy:
runs-on: [ubuntu-latest, x64, small]
needs: prepare
steps:
- name: Use job output
run: |
echo "version=${{ jobs.prepare.outputs.version }}"
echo "status=${{ jobs.prepare.outputs.status }}"

Workflow Output

In a reusable workflow (workflow_call), you can map job outputs to workflow outputs:

name: reusable-build

on:
workflow_call:
outputs:
version:
description: "Build version number"
value: ${{jobs.prepare.outputs.version}}

jobs:
prepare:
runs-on: [ubuntu-latest, x64, small]
steps:
- id: version
run: echo "version=1.0.0" >> "$ATOMGIT_OUTPUT"

Caller receives the output:

jobs:
call-build:
uses: ./.gitcode/workflows/reusable-build.yml
deploy:
needs: call-build
runs-on: [ubuntu-latest, x64, small]
steps:
- name: Use workflow output
run: echo "version=${{ jobs.call-build.outputs.version }}"

Multi-Line Output

Use delimiter syntax when writing multi-line values to ATOMGIT_OUTPUT:

steps:
- id: multiline-output
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "content<<$EOF" >> "$ATOMGIT_OUTPUT"
echo "line1" >> "$ATOMGIT_OUTPUT"
echo "line2" >> "$ATOMGIT_OUTPUT"
echo "$EOF" >> "$ATOMGIT_OUTPUT"