Jenkins Pipeline Replays
Hello and welcome back to my blog! Today we are going to explore the Jenkins Replay feature.
Typically, jenkins pipeline code is written as a script in the job configuration, or you commit it to your git repository and configure the job to pull the appropriate Jenkinsfile at runtime. One big hurdle with Jenkins pipelines for all developers is to figure out how you can iterate and test your pipeline code quickly without spending too much time reconfiguring your job over and over again.
An excellent solution is to make use of Jenkins Pipeline Replay feature! The "Replay" feature allows for quick modifications and execution of an existing Pipeline without changing the Pipeline configuration or creating a new commit.
How to use the Replay Functionality
Follow these simple steps, that are retrieved directly from the Jenkins website.
- Select a previously completed run from the Jenkins build history.
- Click "Replay" in the left menu
- Make modifications and click "Run". In this example, we changed "ruby-2.3" to "ruby-2.4".
- Run the pipeline and check results of your changes!
Jenkins Replay Features
Can be called multiple times on the same run - allows for easy parallel testing of different changes.
Can also be called on Pipeline runs that are still in-progress - As long as a Pipeline contained syntactically correct Groovy and was able to start, it can be Replayed.
Referenced Shared Library code is also modifiable - If a Pipeline run references a Shared Library, the code from the shared library will also be shown and modifiable as part of the Replay page.
Access Control via dedicated "Run / Replay" permission - implied by "Job / Configure". If Pipeline is not configurable (e.g. Branch Pipeline of a Multibranch) or "Job / Configure" is not granted, users still can experiment with Pipeline Definition via Replay
Can be used for Re-run - users lacking "Run / Replay" but who are granted "Job / Build" can still use Replay to run a build again with the same definition.
Limitations of Replays as documented on the Jenkins site
- Pipeline runs with syntax errors cannot be replayed - meaning their code cannot be viewed and any changes made in them cannot be retrieved. When using Replay for more significant modifications, save your changes to a file or editor outside of Jenkins before running them.
- Replayed Pipeline behavior may differ from runs started by other methods - For Pipelines that are not part of a Multi-branch Pipeline, the commit information may differ for the original run and the Replayed run.
Source: https://www.jenkins.io/doc/book/pipeline/development/#replay
And that's all for this one. Hope you learned something new! ☺️