[英]Is there a way to track usage of a global shared library in Jenkins?
Context:语境:
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.