Jenkins Build Steps and Post-Build Actions
Build steps are the instructions Jenkins executes during a build. Post-build actions are the tasks Jenkins performs after the build completes. Together, they define what a job actually does from start to finish.
Think of build steps as the cooking instructions in a recipe. Post-build actions are what you do after cooking — serving the dish, washing the dishes, and letting guests know dinner is ready.
Build Steps: The Work Jenkins Does
Jenkins runs build steps in the order they appear. If one step fails (exits with a non-zero status), Jenkins stops and marks the build as failed. Subsequent steps do not run when a previous one fails — unless you configure otherwise.
Build Step Execution Flow
Build Starts
|
v
Step 1: npm install ← Runs
|
v (Step 1 passed)
Step 2: npm test ← Runs
|
v (Step 2 passed)
Step 3: npm run build ← Runs
|
v (Step 3 passed)
Build Succeeds → Move to Post-Build Actions
---- OR ----
Build Starts
|
v
Step 1: npm install ← Runs
|
v (Step 1 passed)
Step 2: npm test ← FAILS (tests fail)
|
v (Build marked FAILED)
Step 3: npm run build ← SKIPPED
|
v
Build Fails → Move to Post-Build Actions
Common Build Step Types
Execute Shell (Linux and macOS)
The most flexible build step. You write any shell commands, just like you would in a terminal. Jenkins runs them inside the workspace directory.
Example shell commands: # Install dependencies npm install # Run tests and save results npm test -- --reporter junit --reporter-options output=test-results.xml # Build the application npm run build # Package for deployment tar -czf app-$(date +%Y%m%d).tar.gz dist/
Execute Windows Batch Command
The Windows equivalent of Execute Shell. Used on Windows build agents to run .bat or cmd commands.
Example: call npm install call npm test call gradle build
Invoke Top-Level Maven Targets
A dedicated step for Java projects that use Apache Maven. Enter the Maven goals directly without writing a shell command.
Maven Goals: clean test package This is equivalent to running: mvn clean test package from the command line. Common Maven goal combinations: clean compile → Compile only clean test → Compile + run tests clean package → Compile + test + package (creates .jar or .war) clean verify → Full build + integration tests clean deploy → Build + deploy to a Maven repository
Invoke Gradle Script
For Java and Android projects using Gradle. Specify the Gradle tasks to run.
Gradle Tasks: clean test build Equivalent to: ./gradlew clean test build
Run with Timeout
Wrap another build step with a timeout. If the step does not finish within the time limit, Jenkins cancels it and marks the build as failed. This prevents a stuck build from blocking your build queue indefinitely.
Chaining Multiple Build Steps
A single job can have many build steps running in sequence. Use this to break a complex workflow into clear, readable stages.
Job: full-java-build Step 1 (Shell): echo "Starting build for branch: $GIT_BRANCH" Step 2 (Maven): clean compile Step 3 (Maven): test Step 4 (Shell): cp target/*.jar artifacts/ Step 5 (Maven): package -DskipTests
Post-Build Actions: What Happens After
Post-build actions always run — even if the build failed. This is important for notifications and cleanup tasks. You can also configure each action to run only on specific outcomes.
Post-Build Action: Archive the Artifacts
Artifacts are files produced by the build that you want to keep — compiled binaries, JAR files, WAR files, log files, test reports, or installation packages.
Files to archive: target/*.jar
dist/**
reports/*.html
After archiving, the artifacts appear on the job's
build page with a download link.
Build #12
├── Archived Artifacts
│ ├── myapp-1.0.jar ← Download link
│ └── test-report.html ← Download link
Post-Build Action: Publish JUnit Test Results
Many test frameworks (JUnit, TestNG, pytest with the junit plugin) produce XML files with test results. Jenkins reads these files and displays pass/fail counts, test trends, and failure details on the build page.
Test report XMLs: target/surefire-reports/*.xml
test-results/**/*.xml
Jenkins displays:
Tests Run: 47
Failures: 2
Errors: 0
Skipped: 3
And shows a trend graph across builds:
Build #10: 47 pass, 0 fail
Build #11: 45 pass, 2 fail ← Regression detected
Build #12: 47 pass, 0 fail ← Fixed
Post-Build Action: Email Notification
Send an email when a build fails, succeeds, or changes status from the previous run. This keeps the team informed without anyone having to watch the Jenkins dashboard.
Recipients: dev-team@company.com, lead@company.com Jenkins sends an email when: - Build fails - Build recovers after a failure - Build becomes unstable (some tests failing)
Post-Build Action: Trigger Another Job
Start a downstream job after this one completes. This creates a chain of jobs without needing a full Pipeline.
On build success → trigger: integration-tests On build failure → trigger: notify-on-call-team
Post-Build Action: Delete Workspace When Build Is Done
This cleans up temporary build files after each run. Useful for jobs that generate large files and fill up disk space quickly.
Build Result States
| Result | Color | Meaning |
|---|---|---|
| SUCCESS | Blue (or Green with theme) | All steps completed without errors |
| UNSTABLE | Yellow | Build completed but some tests failed |
| FAILURE | Red | A build step exited with an error |
| ABORTED | Grey | A human stopped the build before it finished |
| NOT BUILT | Grey | The build was skipped or never triggered |
Key Points
- Build steps are the commands Jenkins runs — shell scripts, Maven, Gradle, and more.
- Steps run in order; a failure in one step stops the remaining steps.
- Post-build actions handle reporting, notifications, artifact saving, and chaining to other jobs.
- Archiving artifacts saves build outputs to Jenkins so you can download them later.
- Publishing JUnit test results gives Jenkins visibility into test pass/fail trends over time.
