0
0
Jenkinsdevops~5 mins

Post-build actions in Jenkins - Commands & Configuration

Choose your learning style9 modes available
Introduction
After your Jenkins job finishes building your project, you often want to do extra steps like sending notifications or archiving files. Post-build actions let you automate these extra tasks easily.
When you want to send an email alert if the build fails or succeeds.
When you need to save build artifacts like compiled files for later use.
When you want to trigger another Jenkins job after the current one finishes.
When you want to publish test results automatically after the build.
When you want to clean up temporary files or notify a chat channel after build.
Commands
This command starts the Jenkins job named 'my-job' and waits for it to finish so you can see the result.
Terminal
jenkins-cli build my-job -s
Expected OutputExpected
Started build #15 Finished: SUCCESS
-s - Waits for the build to complete before returning.
Shows the console output of build number 15 of 'my-job' so you can check what happened during the build and post-build steps.
Terminal
jenkins-cli console my-job 15
Expected OutputExpected
[Pipeline] echo Build completed successfully [Pipeline] archiveArtifacts Archiving artifacts [Pipeline] mail Sending email notification Finished: SUCCESS
Key Concept

Post-build actions let you automate tasks that happen right after your build finishes, like notifications or saving files.

Common Mistakes
Not configuring any post-build actions, so important steps like notifications never happen.
You miss critical alerts or lose build artifacts because no follow-up tasks run.
Always add needed post-build actions in your Jenkins job configuration to automate these steps.
Configuring post-build actions that depend on files not generated during the build.
The post-build step fails because the expected files are missing.
Ensure your build produces the files before post-build actions try to use them.
Summary
Use post-build actions to automate tasks after your Jenkins build finishes.
Common post-build actions include sending emails, archiving artifacts, and triggering other jobs.
You can run and check your Jenkins job using jenkins-cli commands to verify post-build actions.