> $GITHUB_OUTPUT - name: Use version run: echo "Building version ${{ steps.versioning.outputs.version }}" - name: Tag Docker image run: | docker build -t myapp:${{ steps.versioning.outputs.version }} . docker push myapp:${{ steps.versioning.outputs.version }} The id: field on the producing step is mandatory — without it, later steps have no handle to reference its outputs. The echo "key=value" >> $GITHUB_OUTPUT syntax appends to the output file; you can write multiple outputs from the same step by appending multiple lines. Important: The older ::set-output command (written directly to stdout) was deprecated in 2022 and disabled in 2023 due to injection vulnerabilities. Always use $GITHUB_OUTPUT. For multi-line values, use the heredoc syntax: run: | echo "NOTES<> $GITHUB_OUTPUT cat CHANGELOG.md >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT"> > $GITHUB_OUTPUT - name: Use version run: echo "Building version ${{ steps.versioning.outputs.version }}" - name: Tag Docker image run: | docker build -t myapp:${{ steps.versioning.outputs.version }} . docker push myapp:${{ steps.versioning.outputs.version }} The id: field on the producing step is mandatory — without it, later steps have no handle to reference its outputs. The echo "key=value" >> $GITHUB_OUTPUT syntax appends to the output file; you can write multiple outputs from the same step by appending multiple lines. Important: The older ::set-output command (written directly to stdout) was deprecated in 2022 and disabled in 2023 due to injection vulnerabilities. Always use $GITHUB_OUTPUT. For multi-line values, use the heredoc syntax: run: | echo "NOTES<> $GITHUB_OUTPUT cat CHANGELOG.md >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT" />

Prev Next

Maven / GitHub Actions Interview Questions

How do you share data between steps within a job using step outputs?

Steps within the same job communicate by writing key-value pairs to the special file at the path stored in $GITHUB_OUTPUT. Any subsequent step in the same job can then read that value via ${{ steps.<step-id>.outputs.<name> }}.

jobs:
  pipeline:
    runs-on: ubuntu-latest
    steps:
      - name: Generate version
        id: versioning           # id is required to reference outputs
        run: |
          VERSION="1.4.${{ github.run_number }}"
          echo "version=$VERSION" >> $GITHUB_OUTPUT

      - name: Use version
        run: echo "Building version ${{ steps.versioning.outputs.version }}"

      - name: Tag Docker image
        run: |
          docker build -t myapp:${{ steps.versioning.outputs.version }} .
          docker push myapp:${{ steps.versioning.outputs.version }}

The id: field on the producing step is mandatory — without it, later steps have no handle to reference its outputs. The echo "key=value" >> $GITHUB_OUTPUT syntax appends to the output file; you can write multiple outputs from the same step by appending multiple lines.

Important: The older ::set-output command (written directly to stdout) was deprecated in 2022 and disabled in 2023 due to injection vulnerabilities. Always use $GITHUB_OUTPUT.

For multi-line values, use the heredoc syntax:

run: |
  echo "NOTES<> $GITHUB_OUTPUT
  cat CHANGELOG.md >> $GITHUB_OUTPUT
  echo "EOF" >> $GITHUB_OUTPUT
What environment file do you write to in order to set a step output in modern GitHub Actions?
Which step property is required in order for a later step to reference the first step's outputs?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.

Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

What is GitHub Actions and what problems does it solve? What are the key components of GitHub Actions — workflows, jobs, steps, actions, and runners? How is a GitHub Actions workflow file structured, and where must it be placed? What are workflow triggers (on:) and which event types does GitHub Actions support? What is the difference between push, pull_request, and workflow_dispatch triggers? What are jobs in GitHub Actions, and how do they run in parallel by default? What are steps, and what is the difference between run: and uses: in a step? What are runners, and what is the difference between GitHub-hosted and self-hosted runners? What is the GitHub Actions Marketplace and how do you find and use actions from it? How do you use the actions/checkout action and what does it do? How do you pass environment variables and secrets to a GitHub Actions workflow? What is the difference between the env:, secrets:, and vars: contexts in GitHub Actions? How do you cache dependencies in GitHub Actions using actions/cache? How do you use matrix builds in GitHub Actions to test across multiple environments? How do you control job execution order in GitHub Actions using needs:? How do you share data between steps within a job using step outputs? How do you share build artifacts between jobs using actions/upload-artifact and actions/download-artifact? What are reusable workflows in GitHub Actions and how do you call them? What are composite actions and when should you choose them over reusable workflows? How do you set up a Docker container service for integration tests using services: in GitHub Actions? How do you use conditional steps with if: in GitHub Actions? What are the key GitHub Actions expression contexts and what information does each provide? How do you use concurrency groups to cancel outdated workflow runs in GitHub Actions? What is the GITHUB_TOKEN and what permissions does it have? How do you trigger one GitHub Actions workflow from another using workflow_run? How do you write a custom JavaScript action for GitHub Actions? How do you write a custom Docker container action for GitHub Actions? How do you implement a complete CI/CD pipeline for a container image in GitHub Actions — build, push to a registry, and deploy? How do you implement path filtering so a workflow only runs when specific files change? How do you debug failing GitHub Actions workflows — enabling debug logging and using tmate? How do you implement branch protection rules with required GitHub Actions status checks? How do you handle large monorepos with multiple services in GitHub Actions? What are OpenID Connect (OIDC) tokens in GitHub Actions and how do they replace long-lived cloud credentials? How do you prevent secret exposure and follow security hardening best practices in GitHub Actions? What are the key differences between GitHub Actions, Jenkins, and GitLab CI?
Show more question and Answers...

GitOps Interview Questions

Comments & Discussions