Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start a bash login shell in jenkins pipeline (formerly known as workflow)?

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.

like image 957
Jeff Avatar asked Feb 11 '16 15:02

Jeff


People also ask

How do I start a 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.

What is the step that runs Unix shell scripts in Jenkins pipelines?

On Linux, BSD, and Mac OS (Unix-like) systems, the sh step is used to execute a shell command in a Pipeline.

Does Jenkins use sh or bash?

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.


1 Answers

@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.
'''
like image 98
Jeff Avatar answered Sep 27 '22 20:09

Jeff