Maven / GitHub Actions Interview Questions
How do you use conditional steps with if: in GitHub Actions?
The if: key on a job or step controls whether it executes. It accepts a GitHub Actions expression that evaluates to true or false. When false, the step is skipped and shown as greyed-out in the run log — the job does not fail.
Common patterns:
steps:
# Run only on pushes to main
- name: Deploy to production
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: ./deploy.sh
# Run only when a previous step failed (for alerting)
- name: Notify failure
if: failure()
run: ./send-alert.sh
# Run after always — even if prior steps failed
- name: Upload test report
if: always()
uses: actions/upload-artifact@v4
with:
name: test-report
path: target/surefire-reports/
# Skip on draft pull requests
- name: Run expensive checks
if: github.event.pull_request.draft == false
run: ./full-test-suite.sh
Status-check functions available in if: expressions:
success()— true if all prior steps succeeded (the default behaviour)failure()— true if any prior step failedcancelled()— true if the workflow was cancelledalways()— always true regardless of prior step results
You can also combine expressions: if: success() && github.actor != 'dependabot[bot]'. Note that the ${{ }} wrapper is optional for if: — GitHub automatically evaluates the expression.
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...
