Jenkins Pipeline CPS全局lib资源文件,用于shell脚本 [英] Jenkins Pipeline CPS global lib resource file for shell script purpose

查看:205
本文介绍了Jenkins Pipeline CPS全局lib资源文件,用于shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jenkins的许多项目中都有一个通用的shell脚本,将其放入资源文件夹并按如下所示加载它是否正确:

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'

在此有效:

sh script

但是一旦我开始制作build_push.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...

第二个问题是将script变量输出到临时文件(例如

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'"

推荐答案

bash -c将解决问题.只需记住第一个参数是$ 0而不是$ 1

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

例如:

我的脚本-

 echo hello $0!

在Jenkinsfile中

in Jenkinsfile

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

结果就是世界!

这篇关于Jenkins Pipeline CPS全局lib资源文件,用于shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆