简体   繁体   中英

Is there a way to track usage of a global shared library in Jenkins?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM