Maven / GitHub Actions Interview Questions
How do you control job execution order in GitHub Actions using needs:?
needs: declares that a job must wait for one or more other jobs to succeed before it starts. This turns the default parallel fan-out into a directed acyclic graph (DAG) of dependencies, allowing you to model pipelines like build → test → deploy.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./gradlew jar
test:
runs-on: ubuntu-latest
needs: build # waits for build to succeed
steps:
- run: ./gradlew test
deploy:
runs-on: ubuntu-latest
needs: [build, test] # waits for BOTH build and test to succeed
steps:
- run: ./deploy.sh
If any job listed in needs: fails, the dependent job is automatically skipped (not failed). You can override this with an explicit condition:
notify:
runs-on: ubuntu-latest
needs: deploy
if: always() # runs even if deploy failed
steps:
- run: ./notify-slack.sh
You can also check the result of a specific dependency using needs.<job-id>.result, which returns 'success', 'failure', 'cancelled', or 'skipped'. This lets downstream jobs make fine-grained decisions about what to do based on which upstream step passed or failed.
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...
