Given the following Jenkinsfile:
@NonCPS
void touchFiles() {
sh "touch foo"
sh "touch bar"
}
node('general') {
touchFiles()
sh "ls"
}
I see the following in the console log on Jenkins:
Running on box35 in /internal/slave/build/workspace/1499786637.EXAMPLE_test-repo_test_jenkinsfile
[Pipeline] {
[Pipeline] sh
[1499786637.EXAMPLE_test-repo_test_jenkinsfile] Running shell script
+ touch foo
[Pipeline] sh
[1499786637.EXAMPLE_test-repo_test_jenkinsfile] Running shell script
+ ls
foo
Note that 'bar' has not been created.
Why does only the first sh
run here? How can I factor out a series of sh
calls in a Jenkinsfile?
(I know I could write sh "touch foo; touch bar"
but in more complex Jenkinsfiles I sometimes need separate sh
invocations.)
In addition to the answer from @arifCee, you could do this:
@NonCPS
void touchFiles() {
sh '''
touch foo
touch bar
'''
}
node('general') {
touchFiles()
sh "ls"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With