且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Jenkins管道Groovy脚本调用资源文件中定义的bash函数?

更新时间:2023-12-05 15:18:34

According to the documentation

External libraries may load adjunct files from a resources/ directory using the libraryResource step. The argument is a relative pathname, akin to Java resource loading:

def request = libraryResource 'com/mycorp/pipeline/somelib/request.json'

The file is loaded as a string, suitable for passing to certain APIs or saving to a workspace using writeFile.

It is advisable to use an unique package structure so you do not accidentally conflict with another library.

I assume the following will work

def functions = libraryResource 'com/mycorp/pipeline/somelib/functions.sh'
writeFile file: 'functions.sh', text: functions
sh "source function.sh && foofoo"

相关阅读

推荐文章