I have a declarative pipeline that executes almost regularly. Upon specific condition (evaluated during the job run) I'd like to keep the job longer than usual.
- Usual runs I keep for one week.
- If condition 1 is true I want to keep the build for up to a month.
- If condition 2 is true, I want to keep the build for up to six months.
Can Jenkins do something like that out of the box, or can it do it by adding some plugin?
CodePudding user response:
So I found a solution to this job: Jenkins out of the box cannot do what I was searching for. However Jenkins can run plugins. Not finding any plugin that would satisfy my need I started creating my own. Here are the highlevel steps if someone wanted to do the same:
- follow the Jenkins Plugin development tutorial. From that you have a plugin with a build step and a build action
- modify the build action to store the information about the two conditions, or even better the resulting keep period.
- modify the build step so the information can be set from freestyle builds or pipeline steps.
- create a BuildDiscarder that reads the information from the action and honors it before triggering a delete