This page describes how to configure a Bamboo task to use a script executable. You can use Bash on Linux, and batch files on Windows.

To configure a script task:

  1. Navigate to the Tasks configuration tab for the job (this will be the default job if creating a new plan).
  2. Click the name of the desired script task, or click Add Task and then Script if creating a new task.
  3. Complete the following settings:

    Script configuration
    Task DescriptionA description of the task, which is displayed in Bamboo.
    Script locationSelect the location of the script file.
    • File — enter the location of the file in the Script file field. This can be either relative to the repository root of the plan, or absolute. You can include variables (see Bamboo variables).
    • Inline — enter the script in the Script body field.
    Argument

    Specify an argument to pass to the script. Arguments that contain spaces must be quoted. You can include variables (see Bamboo variables).

  4. If required, specify environment variables and working directory settings:

    Environment Variables

    (Optional)  Additional system environment variables that you want to pass to your build. Note that existing environment variables are automatically available to the executable. You can also include Bamboo global or build-specific variables (see Bamboo variables).
    Multiple variables should be separated with spaces. Parameters with spaces must be quoted (e.g ANT_OPTS="-Xms200m -Xmx700m").

    Working Sub Directory(Optional)  An alternative subdirectory, relative to the job's root directory, where Bamboo will run the executable. The root directory contains everything checked out from the job's configured source repository. If you leave this field blank, Bamboo will look for build files in the root directory. This option is useful if your task has a build script in a subdirectory and the executable needs to be run from within that subdirectory.
    Run as Powershell script(Optional, Windows only) Check the 'Run as Powershell script' checkbox to run the script with Powershell instead of cmd.exe which interprets .bat files. The inline editor supports Powershell syntax.

  5. Click Save.

67 Comments

  1. Anonymous

    Can a script be a python code?

    1. Anonymous

      Only if you use the hacky method of turning a shell script into a python script using heredoc.

  2. Anonymous

    How do I reference my Bamboo variables in bash? It doesn't like the dot in bamboo.variable

    1. Anonymous

      Same problem here.

      1. James Dumay

        Bamboo variables are exported as bash shell variables. The name is converted to capital casing and all full-stops are converted to underscores. For example, the variable bamboo.my.variable is $BAMBOO_MY_VARIABLE in bash.

        1. dustin_barnes

          No, they're not. 

           

          16-Jan-2014 18:29:35Starting task 'Print Env' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
          16-Jan-2014 18:29:35
          Beginning to execute external process for build 'XXXX #5 (XXXX-5)'
          ... running command line:
          /bin/sh /var/tmp/env.sh
          ... in: /opt/atlassian/bamboo/current/xml-data/build-dir/XXXX
          16-Jan-2014 18:29:35TERM=xterm
          16-Jan-2014 18:29:35JAVA_OPTS=-XX:MaxPermSize=256m -Xms256m -Xmx384m   
          16-Jan-2014 18:29:35LD_LIBRARY_PATH=/usr/java/jdk1.6.0_27/jre/lib/amd64/server:/usr/java/jdk1.6.0_27/jre/lib/amd64:/usr/java/jdk1.6.0_27/jre/../lib/amd64
          16-Jan-2014 18:29:35NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat
          16-Jan-2014 18:29:35PATH=/sbin:/usr/sbin:/bin:/usr/bin
          16-Jan-2014 18:29:35_=/bin/env
          16-Jan-2014 18:29:35PWD=/opt/atlassian/bamboo/atlassian-bamboo-5.3/xml-data/build-dir/XXXX
          16-Jan-2014 18:29:35JAVA_HOME=/usr/java/latest
          16-Jan-2014 18:29:35JAVA_PERMGEN_SUPPORTED=true
          16-Jan-2014 18:29:35XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt
          16-Jan-2014 18:29:35SHLVL=4
          16-Jan-2014 18:29:35Finished task 'Print Env'

          The env.sh script is a simple "env" command – because the docs say that the variables are only there for file-type scripts. 

          This seems to be a huge bug with 5.3. 

  3. Anonymous

    How can I let a script (exit code?) tell bamboo to fail the build?

    1. Any non-zero exit code will cause the Script task to fail.

  4. Anonymous

    I can't seem to get any of the bamboo run-time variables to work with my shell script. I'm specifically trying to use bamboo.build.working.directory. Trying to just echo the value from the script (bash script on centos linux):

    echo ${bamboo_build_working_directory}
    echo ${BAMBOO_BUILD_WORKING_DIRECTORY}
    echo $BAMBOO_BUILD_WORKING_DIRECTORY

    all of these return blank lines. 


    1. Karel Bemelmans

      It's just the same: ${bamboo.build.working.directory}

      If you want to see a list of all variables available during a script's runtime, just output 'env' and you will get a list.

    2. dustin_barnes

      You're not alone. I think that feature is just broken on any modern version of Bamboo. It's late Jan 2014, and I'm running into the same problem, but Atlassian seems very disinterested in fixing it. Their roadmaps for fixes aren't even prioritizing it, but don't worry, AWS regions in Asia are getting top support! </sarcasm>

      1. Anonymous

        I'm having the same problem. Do you know if there's a bug submitted? I can't find it.

  5. Anonymous

    I also tried setting up a plan variable that points to ${bamboo.build.working.directory} and then using that plan variable in the shell script. It returns the string ${bamboo.build.working.directory}.

  6. Anonymous

    > How can I let a script tell bamboo to fail the build? 

    return a none-zero

    > then how could i set a custom build failure info?

     

  7. Anonymous

    This is weird. For a Windows agent I defined CScript as a custom executable so that I can run a VBScript using Windows Scripting Host. I have a few named arguments that I quoted to pass to CScript, e.g., /sign /dryrun.

    Bamboo insists on changing the forward slashes to backslashes. How is that useful? My script won't run because it doesn't understand the arguments being fed to it.

     

  8. Ben Kershner

    Is there anyway to force a TTY on the script? I'm trying to use sudo to install a couple of packages (e.g. "sudo apt-get install foo").

    1. Kelly Schoenhofen

      I'm stuck on a similar problem. To get past the issue you're having (or had, as this is 16 days later) I ended up turning off the password prompt for sudo; this seemed preferable to encoding a password into a build. 

      Edit your sudoers file and change the bottom/admin line to the following, then reboot:

      %admin  ALL=NOPASSWD: ALL

      It doesn't give out sudo, it just tells the system not to prompt for your password if you're on the sudoers list. 

  9. Sorin Sbarnea

    Is my impression that this page states that Bamboo will run inline-scripts with bash on Unix and with cmd.exe on Windows and there is no way to change this for inline-scripts? Jenkins allows you to specify the interpreter using the shebang line, allowing you to run the scripts with almost anything.

    1. Kelly Schoenhofen

      Technically, Bamboo uses a non-interative /bin/sh, not bash, unless you add bash via a custom builder (i.e. /bin/bash). I've had very mixed results with that, and have stuck with living with the non-interactive /bin/sh and worked around my issues there.  

      -Kelly

      PS - Atlassian, your captcha system is bugged. I know I'm typing in the right word on the first try, but it frequently insists I'm not. Do not tell me I'm typing it in wrong. Your system is wrong. 

    2. Karel Bemelmans

      You could also just make your own script, have it somewhere available on the build server and then make it available as a script on build server. You then chose "Command" instead of "Script" for a task and just pass in same arguments to your script from Bamboo.

      (I'm using Bamboo Ondemand, no idea if the downloaded version also has this feature)

  10. Anonymous

    What's the advantage of using a script file as described here than using a .bat file registered as executable?

    1. Julian

      I've got the same question...

  11. Kelly Schoenhofen

    Well, inline scripts are handy because you can expose the build them to users (and thus let them control some of the build/deployment process) without giving them write access to your source code repository (if you are storing your build scripts in source control) or the build server itself (if you're relying on scripts/batch files in the system path). 

    Conversely, if you control access to the inline script in Bamboo, you can hide the server-level stuff (like hard-coded credentials) from source control where many people perhaps have at least read access, and keep source control for source, not for deployment batch files used by DevOps/et al. 

    -Kelly

  12. Anonymous

    Hi,

    Can the script be a PERL script?

    Thanks,

  13. Kelly Schoenhofen

    It can be anything you want, as long as you recognize it will be executed by /bin/sh. (on a linux box, for instance). Adjust your bits accordingly; for instance, as an inline script you could do this (I assume):

    python path/to/the/script.py

    Or if you have #!/usr/bin/python at the top of your script, and it's executable, you could just do an inline script like:

    ./path/to/the/script.py

    If you're wondering if you can paste a python script into the inline script editor and get Bamboo to use python to run it - I don't think their custom builder (such as specifying /bin/bash, or /usr/bin/python) allows inline scripting yet, so that's a no. That would be a nice feature to have though. 

    1. Sorin Sbarnea

      No that's impossible with Bamboo and one of the reasons why we are still very happy to use jenkins, as this allows you to provide any inline script, being able to take case of the shebang line across multiple platforms, including Windows. 

      Bamboo doesn't,... I was surprised to dicover this while evaluating the product. Clearly a basic requirement for any build system, not a weird one... still misssing.

      1. James Dumay

        If we changed it to honour the #! at the beginning of the script, would this work for you?

        BAM-13383 - Getting issue details... STATUS

        1. Kelly Schoenhofen

          That change alone would be worth a major release of Bamboo. 

        2. Sorin Sbarnea

          Correct bug  BAM-13383 - Getting issue details... STATUS  ...the previous one is just a duplicate of this (smile)

  14. Kelly Schoenhofen

    This shouldn't be a "Bamboo vs Jenkins" thread - they are different products, with different audiences. Bamboo is a build & deployment orchestrator & integrator. Jenkins is a development tool. While they share many features and uses on a venn diagram, they aren't the same circle. 

    If you're struggling with Bamboo vs Jenkins, then maybe you need to understand your needs a little better; it shouldn't be a fight and you should use the product that fits your needs best, not spend your time & energy forcing a round peg into a square hole. 

    -Kelly

    1. Sorin Sbarnea

      While I agree with you that this should not became such a thread, I should note that both of them are same kind of products, with and almost total overlap, and the proper term would be "continuous integration server". Usually I don't like to quote wikipedia, but you can check. And the living proof is that Bamboo is presented by Atlassian as a posible replacment for Jenkins, as they do provide an import tool inside the product, in fact the only kind of import that you can do.

      1. James Dumay

        You are correct - we do position Bamboo as a replacement for Jenkins. We don't claim to do everything that Jenkins does, but we think there are a number of great areas (For example, Deployment projectsplan branches and JIRA integration) where we think Bamboo really shines.

        As in all products, there are plenty of areas for improvement. If you have any suggestions or feature enhancement ideas, please file them here (I read all the new issues every day).

        1. Sorin Sbarnea

          Here is the bug related to being able to run generic scripts (shebang support):  BAM-13383 - Getting issue details... STATUS  I invite others to add their comments or at least vote if they are about this missing feature.

          1. James Dumay

            Thanks for quoting the right ticked. I closed the one I opened as a duplicate.

        2. dustin_barnes

          James, you have seemed quite active here, but here's 2 issues where I'm seeing Bamboo fail me:

          1. No – and I don't mean "one or two," I mean ZERO – tools to track code quality in 5.2.x and above. Checkstyle, FindBugz, PMD, CPD, jsHint, etc. The excuse has been that they're 3rd party tools, but most of those have first-party support in build tools (maven, gradle, buildr, ...). This is something that is probably going to push us away from Bamboo. 
          2. The bash variable export simply doesn't work. I've filed a ticket for it. It's been broken since early 2013, and nobody seems interested in fixing it. What's the deal with that? 

          I'm just concerned that Bamboo was a bad purchase for our company, and as a consultant, I'll never be able to recommend it to clients. I'm just really confused as to the priorities of feature/bug fixes, because those two issues above seem like minimum viable features for a build server that is free, much less one that is paid. 

           

           

          1. Kelly Schoenhofen

            If your build system should also be your quality & metrics center, than you may want to look at Jenkins. 

            After trying to scale Jenkins up (and failing) I am glad Bamboo doesn't include tools like JaCoCo, JSCover, Sonar, etc. I would rather use Bamboo as our build & deployment orchestration server. Let the builds themselves do Coverity analysis, and keep the core build system out of it. 

            Yes, they include a junit xml parser as a nod to the ubiquity of unit tests failing a build; I consider it a starter block to get you going. If I really needed Bamboo to fail a build if code coverage dropped below 80% all automagically, I would look to the marketplace to supply the plugin. Bamboo's plugin marketplace is pretty thin right now; I think they need more installs to start growing the community. The progress they have made in the last 18 months on the product has been the right thing to do - stopping to write a FindBugz plugin wouldn't make the product more "enterprise" (which is what I'm looking for), it would just chase the Jenkins SKU which is covered quite well by Jenkins. 

            I also have issues with Bamboo:

            • Agent maintenance is completely lacking, I love the pace of Bamboo releases, but I cannot keep up with updating the agents which you have to do by hand.
            • The lack of real bash support is ridiculous. We have too many developers who have cut their teeth on bash for Bamboo to only natively support /bin/sh. 

            Otherwise, I'm still happy with the stability, robustness and Bamboo's core functionality working so well. 

            1. dustin_barnes

              I appreciate your reply. Thanks!

              As for code quality, I just want it tracked. I want a visual chart of how different things work. I think that's a perfectly reasonable thing to look for in a commercial CI system. We are on 5.3 here, and there isn't one single "reporting" plugin. It seems weird that they'd spend all this time writing a reporting infrastructure, but not actually use it for what seems to be the primary use case. I'd be very surprised if Atlassian themselves didn't use and track these metrics. Maybe they have another solution?

               

              1. James Dumay

                We use other in house solutions for performance metrics and a few teams use Findbugs and JMeter plugins to track these metrics.

            2. James Dumay

              Great feedback Kelly.

              As of Bamboo 3.4, Bamboo automatically upgrades Remote Agents when the server version changes which saves you doing this yourself.

              1. Kelly Schoenhofen

                James, if same-sex marriage was legal in Australia, I would fly there tonight. My wife would surely understand. 

                1. James Dumay

                  Hahaha almost died when I read this.

                  You'd have to fight my actual same-sex partner for the privilege (wink)

          2. James Dumay

            Hi Dustin,

            Thanks for the feedback. Is BAM-14218 the ticket in question? We haven't seen any reports that points to this being broken, but ill have someone investigate.

            I agree with you that we need to get better at supporting quality metrics.

            Thanks
            James 

             

            1. dustin_barnes

              Yep, that's the one. Thanks for taking a look at it. I see quite a few people saying that the bash environment variables just don't exist, and I took some steps to prove it. 

              I even spent a chunk of Friday learning the plugin stuff so I could write a quick plugin to spit that info out into a properties file so it could be consumed by the rest of the build process, but I'd prefer to not have to maintain that (smile)

              1. James Dumay

                Its on the top of our backlog but it may not make it into 5.4 (due in approx. two weeks) as we are committed to the work in our last sprint.

  15. saravanan subramanian

    Hi,

     

    using the inline scripts - users are able to rename the files in bamboo_home?  how can we prevent this from happening

    1. James Dumay

      The only way to prevent this is to run remote agents on different user accounts on the same machine that do not have read or write access to the bamboo home.

  16. Anonymous

    How can I get Bamboo to run a script on Win2k8r2 in 32 bit mode? I need it to remap the paths to Program files, etc just as a script run by the 32 bit version of cmd.exe on a 64 bit OS would.

  17. Anonymous

    Add an executable task instead of the script task. pass in your powershell that way. Set it up in admin using 32 bit.

  18. Aris Green

    I'm confused, from a script task that calls the OS's shell, be it cmd.exe on Windows or bash on Linux, just get that to call you Python, Groovy, Ruby, whatever the heck you want.  I think you can get what you need with just that. Parameters can be based to the shell script via the command line and/or environment variables.  Yeah, inline Python scripts might be nice, but you can just have the shell call that in a script.  I guess with Windows, you can call a PowerShell script directly.  I am new to Bamboo, what I would like to learn is how to have a shell script return values back to Bamboo for conditional logic.  With Jenkins, the script can write out to a Java properties file and the values read by in via the EnvInject plugin.

    1. ArmenA

      Hi Aris,

      Bamboo doesn't have an embedded capability to play with the return values; all non-zero values are considered fail and 0 is success. If you want to have more control over the return values, please consider calling a script from a script file, catch the return value, and make sure that the initial one returns 0 if you want it to succeed.

      Armen

  19. Mehul Sanghvi

    I have a simple in-line script:

    rm -rf /scratch/target-dir
    cp -rv src/target-dir /scratch
    chmod -R 777 /scratch/target-dir
    rm -rf /scratch/some-app
    cp -rv src/some-app /scratch

    It gets to the last line, executes the command, and causes the agent to crash.  I don't believe there is anything wrong with the script, is there ?

     

     

    1. Mehul Sanghvi

      Got it wrong.  The above lines of script do not cause a problem.  What is causing the problem is the task that follows the above mentioned task.  It is a script, in a file, not in-line, and it does not even make it to the first command in the script:

       

      #!/bin/sh
      ##################################################################
      echo "Testing to see if some_var is an environment variable: $SOME_VAR"

       

      The output of the echo does not show up anywhere in the logs

      1. Kelly Schoenhofen

        I have seen the same thing, and it's standard practice here to take out all #'d lines in inline scripts. I can usually get by with one but not two in a row. 

        It's irritating because there are times when I really would like some script documentation for the next person to see, or I need to comment out (via #) a chunk of lines temporarily in a inline script and I can't because of this limitation. 

        -Kelly Schoenhofen

        1. Mehul Sanghvi

          Solved!

          Turned out to be an errant ps/kill combination.  The Bamboo agent process was being killed because it was not filtered out of the output from ps.

           

  20. Mehul Sanghvi

    Why does Bamboo have to prefix all environment variables with "bamboo_" ?   If I have a plan variable called FOO_BAR, I want it passed to the shell as an environment variable called FOO_BAR not bamboo_FOO_BAR.  I now have to go through and edit about 117 files and change them to use bamboo_*.  No other build system does that.

     

    I can understand converting to upper case and replacing "." with "_", but actually adding a prefix that was not specified does not seem right at all.  It causes vendor lock-in.  If I at some later point want to switch to something else, I have to make changes to scripts that I should never have had to change in the first place.

     

     

  21. Anonymous

    Hi,

    We have a deployment script we run on our server that does the following:

    1. Checks out the repo in a separate folder
    2. Runs rsync --dry-run with live site files and shows files that will be changed
    3. Requires a deploy y/n response

    Is it at all possible to implement this command with Bamboo so that we could see what the deployment will do exactly from the Bamboo interface and then give the go ahead?

  22. Kelly Schoenhofen

    Bamboo runs its tasks in a non-interactive window, so on the face of it, no. 

    You could make some kludge where it could write the results to a DB and twiddle its electronic thumbs while you decide yay or nay, periodically checking for a yay (or nay). 

    Or, break this up into multiple stages and put an approval process in between the stages. 

  23. Anonymous

    Can my script leave behind environment variables for the next tasks?

  24. Mehul Sanghvi

    Each script task will run in its own process space, so when the task ends, that process space is destroyed as are its child processes.   When that happens, the environment of the process, and the script, is destroyed as well.

    What you could do, is probably write out the environment, as one of the last things you do before the end of the task, to a file in some common location, that subsequent tasks can access, modify, etc.  as needed.

    Hope that helps.

  25. Christian Marth

    I'm trying to use script to generate a variable which contains a git log, which i can acces as a variable in a subsequent task, the log contains multiple lines,

    git log --no-merges --pretty=format:"* %s" ${bamboo.repository.previous.revision.number}..${bamboo.repository.revision.number}>changelog.txt

    I'm successfully able to write this out to a file but am having issues trying to access it in the inject variables plugin, is there a simpler way to do this by using the script to set a variable?

    1. James Dumay

      I believe variables have a limit of 256 characters so this might not be the best approach. 

      Can you tell me a little bit more about what you are trying to achieve? What task do you want to pass it to?

      1. Christian Marth

        I'm trying to pass it to hockeyapp as a Release Notes... I'm probably better writing this functionality in the Xcode plugin.

  26. Ben Bailey

    Please help.  I am running a .bat file using the onDemand version on Bamboo against a windows EC2 machine.  The batch file is clearly being executed by the "bamboo" user.  To run this batch file requires admin privileges.  How can I run my batch file as an admin user automatically? 

     

    Am I being blocked by this bug?  BAM-14097 - Getting issue details... STATUS

  27. Mark Gillespie

    This REALLY needs to talk about exit values/return codes.  I came here looking for this, and there is not a single mention of this, which for a build system is pretty fundamental.

    1. NathanA

      Hi Mark,

      This page is about how to configure your script to run. What sort of information about exit values/return codes are you after? Output format? 

      Let me know and I will see if this is a hole that needs plugging in our docs.

      Cheers,

      Nathan

      1. Sylvain Gil

        Hi Nathan,

        I came here wondering how the task success/status would be impacted by the exit code of the invoked script. In other words, what is the proper way to signal to the task that the script has executed properly or not.

         

        Thanks,

        Sylvain

  28. Max Kalb

    i get

    command	16-Apr-2014 17:31:17	Beginning to execute external process for build 'Scanity - Build Scanity - Build ext #17 (SCAN-SCAN-BE-17)'\n ... running command line: \n/bin/sh /tmp/SCAN-SCAN-BE-17-ScriptBuildTask-7101257030486225774.sh\n ... in: /root/bamboo-agent-home/xml-data/build-dir/SCAN-SCAN-BE/ext\n
    simple	16-Apr-2014 17:31:17	Failing task since return code of [/bin/sh /tmp/SCAN-SCAN-BE-17-ScriptBuildTask-7101257030486225774.sh] was -1 while expected 0
    so i'm simply unable to execute a "Hello World" echo script contains: echo "Hello World"