2

Context:

  • At my work most developers are free to write their own Jenkinsfile for their own team's projects.
  • As the Jenkins admin, I provide developers with a global shared library.
  • Most projects are using either v1 or v2 or v3 or another version of this library, using the idiom library("theSharedLib@v#").

Question: Is there a way for me to find out which Jenkinsfile is using which version of the shared library without having to actually lookup into all those Jenkinsfile files (50+ files in as much git repos)?

What I would see best is some mechanism that write up (into a file on the Jenkins master or in a DB) which project/Jenkinsfile is using which version at the time the library is loaded.

A possible solution would be to add some code to every function inside the library that will actually do this reporting. I could then see which function is used by who. Any better solution?

  • 1
    Side note: Having this knowledge helps in knowing who could be affected by breaking changes in the library and notify them upfront. I need to know who are my library users. – Eric St-Amand Dec 27 '19 at 17:38
  • If you only use a master, or a very small number of agents, just running a grep on the jenkins workspace directory would take only a minute: `find /home/jenkins/workspace -name "Jenkinsfile" -exec grep -H 'theSharedLib' '{}' \;` However, if you have hundreds of agents, that's probably not practical – Mzzl Jan 17 '20 at 18:12
  • That sounds like a good idea for a small setup, as you mention. However, I do have around 70 agents, mixed between Windows and Linux (multiple versions). Well, I could put Nagios on this. Thanks for your idea! – Eric St-Amand Jan 20 '20 at 15:26
  • Maybe you could grep the logs of the git repo where theSharedLib is hosted. I starred this question in case someone comes up with a good jenkins based solution. – Mzzl Jan 21 '20 at 13:08

1 Answers1

0

I wrote https://github.com/CiscoDevNet/es-logger to gather information such as this from Jenkins. It has a plugin that will run a regex against the console log of a completed job and can then post events to elastic search.

Jenkins helpfully posts library loads at the start of the log such as:

Loading library sharedLib@version

So a simple regex like

"^Loading library\S+(?P<library_name>.*?)@(?P<library_version>.*?)\S+$"

added to the console_log_events plugin would generate events in an elastic search for each usage and each version.

j3p0uk
  • 111
  • 1
  • 5