Step Outputs
Passing data between Steps — using $COLLABOPS_OUTPUT and the steps context
Values generated in a step can be referenced by other steps. Store them in the $COLLABOPS_OUTPUT file as key=value pairs, and read them with $\{\{ steps.<id>.outputs.<key> \}\}.
Basic Usage
steps:
# 1. Store output values — you must specify an id
- name: prepare
id: meta # Identifier for referencing from other steps
image: node:18
run: |
# Store as key=value in $COLLABOPS_OUTPUT
echo "version=1.2.3" >> $COLLABOPS_OUTPUT
echo "timestamp=$(date -u +%Y%m%dT%H%M%S)" >> $COLLABOPS_OUTPUT
# 2. Reference output values — using steps.<id>.outputs.<key> format
- name: use-output
image: alpine:3.19
run: |
echo "Version: ${{ steps.meta.outputs.version }}"
echo "Timestamp: ${{ steps.meta.outputs.timestamp }}"Practical Example: Extracting Version from package.json
steps:
- name: checkout
uses: "collabops/checkout@v2"
with:
repo-url: "https://<collabops-host>/<workspace>/<repository>.git"
# Extract version from package.json and store it in the output
- name: extract-version
id: pkg
image: node:18
run: |
VERSION=$(node -p "require('./package.json').version")
echo "app_version=${VERSION}" >> $COLLABOPS_OUTPUT
echo "Extracted version: ${VERSION}"
# Tag the Docker image with the extracted version
- name: build-image
uses: "collabops/docker-build-push@v1"
with:
tags: "my-registry/my-app:${{ steps.pkg.outputs.app_version }}"Practical Example: Collecting Git Information
steps:
- name: checkout
uses: "collabops/checkout@v2"
with:
repo-url: "https://<collabops-host>/<workspace>/<repository>.git"
fetch-depth: "0" # Full history required (for tag lookup)
# Extract various information from Git
- name: git-info
id: git
image: alpine/git:2.43.0
run: |
cd /workspace/source
# Latest tag
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "latest_tag=${LATEST_TAG}" >> $COLLABOPS_OUTPUT
# Short SHA
SHORT_SHA=$(git rev-parse --short HEAD)
echo "short_sha=${SHORT_SHA}" >> $COLLABOPS_OUTPUT
# Commit count (since last tag)
COMMIT_COUNT=$(git rev-list ${LATEST_TAG}..HEAD --count 2>/dev/null || echo "0")
echo "commit_count=${COMMIT_COUNT}" >> $COLLABOPS_OUTPUT
# Create image tag from the collected information
- name: tag-image
run: |
echo "Tag: ${{ steps.git.outputs.latest_tag }}"
echo "SHA: ${{ steps.git.outputs.short_sha }}"
echo "Commits since tag: ${{ steps.git.outputs.commit_count }}"Storing Multiple Output Values
Store multiple key=value pairs in $COLLABOPS_OUTPUT, separated by newlines.
- name: collect-metadata
id: metadata
run: |
# Store multiple values at once
echo "build_number=42" >> $COLLABOPS_OUTPUT
echo "git_branch=${{ collabops.ref_name }}" >> $COLLABOPS_OUTPUT
echo "git_sha=${{ collabops.sha }}" >> $COLLABOPS_OUTPUT
echo "build_date=$(date -u +%Y-%m-%d)" >> $COLLABOPS_OUTPUTRules
If you do not specify an id, you cannot reference the outputs of that step.
Only key=value format is supported in $COLLABOPS_OUTPUT.
Do not use spaces or special characters in keys.
Output values can only be referenced by subsequent steps within the same job. Passing output values between jobs is currently not supported.
This follows the same pattern as step output variables in other CI/CD tools.