简体   繁体   English

使用 Groovy 库的 Jenkins 工作流插件

[英]Jenkins Workflow Plugin Using a Groovy Library

As I'm writing more and more Groovy to use with the Jenkins Workflow plugin I've started getting to the point where I've got re-usable code that could be used in multiple scripts.随着我编写越来越多的 Groovy 与 Jenkins Workflow 插件一起使用,我已经开始获得可在多个脚本中使用的可重用代码。

What would be the best way of sharing this code?共享此代码的最佳方式是什么? Is it possible to produce my own .jar with the shared code in and utilize this from within the Workflow script?是否可以使用共享代码生成我自己的 .jar 并在工作流脚本中使用它? Or is there a simpler way?或者有更简单的方法吗?

You can use Global Lib as pointed in other comments and/or use the load step to load you own scripts from somewhere (ie your SCM just checked out previously).您可以使用其他注释中指出的 Global Lib 和/或使用load步骤从某处加载您自己的脚本(即您的 SCM 之前刚刚签出)。

More info about load : https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md#triggering-manual-loading有关load更多信息: https : //github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md#triggering-manual-loading

This is what the Workflow Global Library is for!这就是工作流全局库的用途! https://github.com/jenkinsci/workflow-plugin/blob/master/cps-global-lib/README.md I use this in my installation, it's a great feature of Workflow. https://github.com/jenkinsci/workflow-plugin/blob/master/cps-global-lib/README.md我在我的安装中使用它,它是 Workflow 的一个很棒的功能。 Right now I just have one "helper" class that contains methods common to all builds, but as other teams start to adopt Workflow they are showing interest in creating their own classes to use for subsets of our builds.现在我只有一个“助手”类,其中包含所有构建通用的方法,但是随着其他团队开始采用 Workflow,他们对创建自己的类以用于我们构建的子集表现出兴趣。

实际上,我最终通过使用我们自己的 git 存储库完成了这项工作,但将符号链接放入工作流库/ src 以指向该存储库。

Workflow Remote File Loader 插件可能会满足您的需求。

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

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