I am just starting to convert my Jenkins jobs into the new Jenkins Pipeline(workflow) tool, and I'm having trouble getting the sh
command to use a bash login shell.
I've tried
sh '''
#!/bin/bash -l
echo $0
'''
but the echo $0
command is always being executed in an interactive shell, rather then a bash login shell.
Start a login shellPress the menu button in the top-right corner of the window and select Preferences. In the sidebar, select your current profile in the Profiles section. Select Command. Under the Command label, select Run command as a login shell.
On Linux, BSD, and Mac OS (Unix-like) systems, the sh step is used to execute a shell command in a Pipeline.
Jenkins by default looks for sh in the PATH environment variable, however the result (e.g. /bin/sh ) may point to different shells. For example, on Ubuntu 6.10 or later, /bin/sh is a symlink to Dash.
@izzekil is right!!!! Thank you so much!
So to elaborate a little bit about what is going on. I used sh
with '''
, which indicates a multiple line script. HOWEVER, the resulting shell script that gets dumped on to the jenkins node will be one line down, rather then the first line. So I was able to fix this with this
sh '''#!/bin/bash -l
echo $0
# more stuff I needed to do,
# like use rvm, which doesn't work with shell, it needs bash.
'''
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