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
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
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...
