简体   繁体   English

有没有办法跟踪 Jenkins 中全局共享库的使用情况?

[英]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.在我的工作中,大多数开发人员可以自由地为自己团队的项目编写自己的 Jenkinsfile。
  • As the Jenkins admin, I provide developers with a global shared library.作为 Jenkins 管理员,我为开发人员提供了一个全局共享库。
  • Most projects are using either v1 or v2 or v3 or another version of this library, using the idiom library("theSharedLib@v#") .大多数项目都使用 v1 或 v2 或 v3 或此库的其他版本,使用惯用语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)?问题:有没有办法让我找出哪个 Jenkinsfile 正在使用哪个版本的共享库,而不必实际查找所有这些 Jenkinsfile 文件(50 多个 git 存储库中的文件)?

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.我最想看到的是某种机制,可以在加载库时记录哪个项目/Jenkinsfile 正在使用哪个版本(在 Jenkins master 上的文件中或在 DB 中)。

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.我写了https://github.com/CiscoDevNet/es-logger来从 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: Jenkins 在日志的开头发布了库加载,例如:

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.添加到 console_log_events 插件将在弹性搜索中为每个用法和每个版本生成事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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