简体   繁体   中英

Jenkins Pipeline CPS global lib resource file for shell script purpose

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM