Search code examples
jenkinsjenkins-pipeline

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 than a bash login shell.


Solution

  • @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.
    '''