简体   繁体   中英

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.

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? 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).

More info about 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. 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.

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

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

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