Skip to main content

Pre-Step and Post-Build in Jenkins

Introduction

In Jenkins, build steps can be categorized into pre-steps and post-build actions, each serving different purposes during a job's execution.

Key Differences

FeaturePre-StepPost-Build Action
Execution TimingRuns before the main build stepRuns after the main build step
PurposeUsed to set up prerequisites (e.g., checking out code, setting environment variables)Used for actions after build completion (e.g., notifications, reports, artifact publishing)
Common UsageCode checkout, dependency installation, environment setupTest report generation, deployment, notifications, cleanup
Impact on BuildCan influence how the main build step executesDoes not affect the build process but acts on its results
Failure HandlingIf it fails, the build might not proceedIf it fails, it does not affect the build execution but may impact post-processing

When to Use Which?

  • Pre-Step: Use when setting up necessary conditions before running the main build (e.g., preparing dependencies, initializing configurations).
  • Post-Build: Use when handling results of the build process, such as sending notifications, publishing artifacts, or archiving reports.

Conclusion

Pre-steps and post-build actions serve distinct roles in Jenkins jobs. Pre-steps prepare the environment before execution, while post-build actions process the results afterward. Understanding these differences helps in designing efficient and robust CI/CD pipelines.