Jenkins Pipeline CPS global lib resource file for shell script purpose

我是研究僧i 提交于 2019-12-25 04:14:16

问题


I have a shell script that is common for many projects in side Jenkins, is it correct to put it into the resources folder and load it as below:

def script = libraryResource 'build/package_indexes/build_push.sh'

while this works:

sh script

but once I start making the build_push.sh script to accept arguments, it won't work since script is not a file...

Second question is that is it correct to output that script variable into a temp file such as

writeFile script '/tmp/tmp.sh'
sh "/tmp/tmp.sh 'cmd_arg'"

回答1:


bash -c will do the trick. just remember that the first param is $0 and not $1

for example:

my script -

 echo hello $0!

in Jenkinsfile

 def script = libraryResource 'hello.sh'
 sh "bash -c '$script' world"

and the result is hello world!



来源:https://stackoverflow.com/questions/40965725/jenkins-pipeline-cps-global-lib-resource-file-for-shell-script-purpose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!