Reputation: 6043
How can I make Jenkins use Bash rather than its native shell for just one Jenkins pipeline/Jenkinsfile? Does the "agent" help me to do this?
I wrote a shell script for deployment but some of the parameters contain whitespace which messes up the resulting command I generate by losing some args. I've found how to avoid this problem by globally configuring Jenkins shell type to be Bash. But when I change the global shell type, my other Jenkins pipelines that use the Jenkins docker plugin syntax get broken when they use the 'sh' command within a docker container. My workaround is to ping pong the global setting for shell type depending on which Jenkins build I want to run. Its a royal PITA.
Upvotes: 3
Views: 2122
Reputation: 6043
I'm embarrassed to say all I needed was a shebang.
My Jenkinsfile runs a custom (bash) shell script, using Jenkin's sh command, like in the following:
sh "./deploy.sh \"arg1\" \"arg 2\" \"arg3\""
In order to force deploy.sh
to run within Bash, the contents of deploy.sh
need to include #!/bin/bash
on the first line, as in:
#!/bin/bash
echo "deploy args: $@"
Regardless, I think there should be a way to tell a Jenkins pipeline that it should run with specific settings, like sh=bash.
Upvotes: 1