Force All Jenkins Pipelines to Call Function?

224 views Asked by At

I work at a company with hundreds of Jenkins pipelines defined.

We have a set of scans we want every pipeline to run (SonarQube, Checkmarx, Blackduck, etc). Is there a way that I can write a function that is automatically called at the end of every single pipeline? I don't want to have to go into every single one of our hundreds of Jenkinsfiles and add in a post block to each of them... I'm looking for something more like a hook that automatically fires at the end of every job, without all of the jobs needing to have their configuration changed.

I've gone through the Jenkins documentation and looked over the list of plugins that exist already and wasn't able to see anything that looked promising.

So far the only possibility I've come up with is having a pipeline which runs nightly, finds every single Jenkinsfile on every repo within our git, and runs a test using Jenkins Pipeline Unit to verify that all of the expected functions are called and email the maintainers if they've omitted anything. This sounds like a lot of effort for something that I would think is a fairly common need?

1

There are 1 answers

1
Yonatan Huber On

I am not 100% sure, but a Freestyle Jenkins job can be set to trigger "Build after other projects are built". It even says "This is convenient for running an extensive test after a build is complete, for example."

I checked this on a Maven project and a Pipeline project and it works. It seems to not work on multibranch-pipeline projects (It fails to recognize them).

This is a bit backward, but you can just list all projects in this trigger line.

There is also this plugin https://plugins.jenkins.io/join/