Jenkins stage mandatory

Hi Everyone,

I am writing to seek your assistance regarding the enforcement of specific stages within our Jenkins pipelines. It is crucial that we make the SonarStage mandatory for all pipelines, as well as ensure that log retention is enforced uniformly across them. Additionally, I would like to implement a policy where the workspace is deleted automatically upon the completion of each pipeline.

We have provided our customers with a default Jenkins file that includes these essential stages; however, it has come to my attention that some users are removing these stages from their configurations. To maintain consistency and quality in our processes, it is imperative that we enforce these requirements across all pipelines.

Could you please provide detailed guidance on how we can achieve this? Specifically, I would appreciate insights on:

  1. How to configure Jenkins to make the SonarStage mandatory.

  2. Steps required to enforce log retention for all pipelines.

  3. Methods to automatically delete workspaces post-pipeline completion.

Your expertise on this matter would be invaluable, and I look forward to your detailed response.

Thank you for your assistance.

Regards,
Venkateswar

For point 2 you should install the Build Discarder plugin. So you can ensure that if no discarder is configured via the pipeline itself, the global one gets active. Jenkins also comes with a global discarder that will always be applied. When you use this the only thing you can do in a job is to configure a shorter period.

For point 1, I think this is not possible
For point 3, consider that a pipeline job can make use of multiple workspaces on different agents. I’m not aware of anything that can do this as of now, but it might be possible to write a plugin that can do this.