问题描述
我们使用插件来分解代码共同对我们不同的Jenkins管道。
中,它为非Groovy文件提供了一个 div>
根据
p>
def请求= libraryResource'com / mycorp / pipeline / somelib / request.json'
我假设以下方法可行
def functions = libraryResource'com / mycorp / pipeline / somelib / functions.sh'
writeFile file:'functions.sh',text :函数
shsource function.sh&& foofoo
We are using the Pipeline Shared Libraries plugin to factorize the code common to our different Jenkins pipelines.
From its documentation, it offers a resources top-level folder for non-Groovy files. As we rely on different bash functions, we would like to host them in a separate .sh file (thus they could also be used by other processes than Jenkins).The same documentation tells us about using libraryResource step to load those resource files. We can successfully call this method within our Groovy script, giving it our resource file name as argument (function.sh). But from here, we were not able to find a way to invoke the foofoo function defined in function.sh from the same Groovy script.
sh "foofoo" #error: foofoo is not defined
We also tried to first source it like this:
sh "source function.sh && foofoo"
But it fails at the source step, stating that function.sh is not found.
What would be the correct procedure to invoke a bash function defined in function.sh
According to the documentation
def request = libraryResource 'com/mycorp/pipeline/somelib/request.json'
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"
这篇关于如何从Jenkins管道Groovy脚本调用资源文件中定义的bash函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!