Sunday, June 25, 2023

How to configure Jenkins to Skip builds based on previous Commit ID

 To configure Jenkins Job Cacher for comparing commit IDs and skipping builds based on changes, you can follow these steps:

Install Jenkins Job Cacher Plugin: In the Jenkins dashboard, navigate to "Manage Jenkins" > "Manage Plugins." In the "Available" tab, search for "Jenkins Job Cacher" and install the plugin.

Configure Global Settings: Once the plugin is installed, go to "Manage Jenkins" > "Configure System." Scroll down to the "Jenkins Job Cacher" section and configure the global settings as follows:


Enable the "Enable job cacher" checkbox.

Set the "Max build history" to an appropriate value to limit the number of builds to compare against.

Configure the "Commit ID extraction" pattern to extract the commit ID from the relevant SCM (Source Control Management) field. This pattern should match the commit ID format used in your SCM.

Configure Job-Level Settings: Open the configuration of the specific Jenkins job for which you want to compare commit IDs and skip builds.


Enable Job Cacher: Scroll down to the "Build Environment" section in the job configuration. Check the "Enable Job Cacher" checkbox.


Configure Build Skip Criteria: In the "Job Cacher Settings" section, configure the build skip criteria:


Select the appropriate SCM field that contains the commit ID from the dropdown.

Specify the build skip behavior based on commit ID changes. You can choose to skip the build when the commit ID is the same as the previous build or when it is different.

Save the Job Configuration: After configuring the build skip criteria, save the job configuration.


Now, when a build is triggered for the configured job, Jenkins will compare the commit ID with the previous build's commit ID. Depending on the configured criteria, the build will be skipped if the commit ID matches or not, thus avoiding unnecessary builds.


Note: Ensure that your Jenkins job is configured to trigger builds automatically, such as on SCM changes or a schedule, for the commit ID comparison and build skipping mechanism to come into effect.

No comments:

Post a Comment