Jenkins Workflow Plugin Using a Groovy Library

2019-04-13 14:45发布

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?

4条回答
对你真心纯属浪费
2楼-- · 2019-04-13 15:05

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.

查看更多
倾城 Initia
3楼-- · 2019-04-13 15:07

I've actually got this working in the end by using our own git repo but putting a symlink into workflow-libs/src to point at that repo.

查看更多
唯我独甜
4楼-- · 2019-04-13 15:08

The Workflow Remote File Loader plugin might meet your needs.

查看更多
SAY GOODBYE
5楼-- · 2019-04-13 15:22

You can use Global Lib as pointed in other comments and/or use the load step to load you own scripts from somewhere (i.e. your SCM just checked out previously).

More info about load: https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md#triggering-manual-loading

查看更多
登录 后发表回答