Making a Bamboo Script execute using /bin/bash

dustingooding January 9, 2012

I need to run a script using /bin/bash instead of /bin/sh, but I'm not seeing a way to do that.

In the logs, I see that /bin/sh is used to execute my script. In my script, I print out the $SHELL variable, and nothing shows up on the screen. So, I assume it's /bin/sh that's being used to run the script... but I can't confirm it. Putting #!/bin/bash at the top of my script doesn't help.

The reason I need to use /bin/bash is that a process I need to start requires a set of environment variables to be set using a an inline function (e.g., source `rosstack find orocos_toolchain`/env.sh) but I don't believe /bin/sh supports that, or the source call.

4 answers

1 accepted

1 vote
Answer accepted
Colin Goudie
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 10, 2012

You should be able to add a new builder from the builders admin menu {URL}/admin/agent/viewBuilders.action

e.g. on our Bamboo instance our Bash builder uses /bin/bash

JulioAmerica May 12, 2017

Good Day

I currently have this problem and not sure where to find this builders admin menu.  Our system actually runs on bin\ksh but bin\bash will do for this instance as we just need a script to run

Could you possibly send a screenshot.

I am using Bamboo:

Bamboo version information
Version5.11.1.1
Build number51117
Build date 4/28/16

 

Please help

John Gill March 20, 2018

In Bamboo 6.1 you can add a script command and have it run in sh or bash or ps. 

Not sure if this helps since you're on 5.11 

The solution above was for Bamboo Cloud. 

Like 唐晓健 likes this
16 votes
Jonathan Loesch June 19, 2014

The accepted answer works if you are running a "command" task from bamboo (i.e. execute a script file).

If you are trying to run a "script" task, which is just running an inline script, you can try putting this snippet at the top to force it to execute in bash. It's a hack, but it worked for me:

#!/bin/bash

if [ "$(ps -p "$$" -o comm=)" != "bash" ]; then
    # Taken from http://unix-linux.questionfor.info/q_unix-linux-programming_85038.html
    bash "$0" "$@"
    exit "$?"
fi
samfulton July 16, 2014

Champion! worked for me

Jerry Henley February 17, 2015

Very nice! Thanks!

Kevin Ross September 29, 2015

Woohoo! Thanks. You would expect this to be simpler with bamboo....Atlassian, are you listening?

Frank Weindel January 29, 2016

No. Atlassian has no time for small fundamental details

Frank Weindel January 29, 2016

This really sucks when you have to bootstrap it in 30 different script tasks.

ABA June 26, 2016

I was able to achieve this by adding below to my script itself

#!/bin/bash

 

JulioAmerica May 12, 2017

Tried this but did not work for me

Like # people like this
Aaron Yang January 18, 2021

Doesn't work, my Bamboo version is 6.9.2.

2 votes
Jurgen Schober January 28, 2019

if you use git/sh use 

#!C:\PROGRA~1\Git\bin\sh.exe

in your shebang line (first line in inline script)

It's an absolute path. You can run any interpreter this way (cygwin/mingw). Please note: no spaces in the file name!

2 votes
Cintia Calvo April 13, 2017

In Bamboo < 5.13, on the agents, if the non-login shell is bash, it should work adding the she-bang on script tasks. 

You can achieve that by linking /bin/sh to /bin/bash, instead of /bin/dash or whatever.

 

From 5.13, it should work regardless of your non-login shell.

https://confluence.atlassian.com/bamboo/bamboo-5-13-release-notes-829057609.html

JulioAmerica May 12, 2017

How can I achieve this without upgrading.

Currently running:

Bamboo version information
Version5.11.1.1
Build number51117
Build date4/28/16

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events