Problem
Jenkins is a great tool for automation server, with a huge number of available plugins. As such it is sometimes hard to find the right one. As I navigated across the sea of automation, there was always a concern -> How do we restore a previous build if the current build completes, but the deployed version has a non-expected error.
Setting up a rebuild scenario in Jenkins brought to life a new dimension issues I was not expecting.
Solution
I completed the requirement by using the Rebuild plugin which adds a nice rebuild button to all the old builds. Got to the plugins page and check for Rebuild plugin. Restart Jenkins afterward just so we are sure everything is picked up correctly. The button to rebuild will be present in the old build details in every project. Rebuild will trigger the build with same configuration as the original build was build with. The issue is that when using a versioning system (like GIT), the configuration stays the same. In my case it was still building the latest commit to the repository as the project was configured to get the latest version.
The solution is to set a string parameter to your job. I set my parameter default value to develop as if no parameter is specified to I want to download the latest version of the develop branch.
String parameter:
- Name: COMMIT
- Default value: develop
Branches to build set to value: ${COMMIT}.
Afterward I can run a Build with Parameters and input a git revision of a previous build.
To rebuild using old code check the old job details (revision number):
then go to the project and press Build with parameters button.
Paste the git revision in the input field and lunch the build.
This way Jenkins builds (and deploys if configured) the current application with the requested revision from GIT.
Hope it help anyone.
Leave a Reply