Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Is there a bamboo variable with the build job's result?

Ken Wood Rising Star Sep 21, 2012

Is there a bamboo variable with the build job's result? I cannot find one in the docs...

I have this situation:

1. In the first stage I need to start a server.

2. In every subsequent stage, if the job or jobs suceed, I need to leave the server running for the next stage

3. After the last server related stage, I'll have a final stage to shutdown the server.

The problem is, between 1.) and 3.), if any job fails I need to shutdown the server because the build will never get to the final cleanup stage.

I have a cleanup script I want to put into each job's 'final task', but if the job succeeded I want to skip the final task so the build can go on to the next stage WITHOUT DOING CLEANUP.

According to the docs, the 'final task' is always run, so I have to put a conditional in the script called from the final task so I can leave the server running if the job succeeded, and kill the server if the job failed.

10 answers

1 accepted

3 votes
Answer accepted
ArmenA Rising Star Dec 26, 2012

Hi Kenneth,

Thanks for the question. I am not sure if you found a way to realise your plans (the question was raised in September), but I will still try to provide some useful information. As far as I understand, all you need is a conditional to check the states of your jobs.

  1. As per Bamboo's REST API documentation, you can use a REST API call from a Script task to check if a specific job failed (state="Failed") or succeeded (state="Successful"):
    curl -X GET --user admin:admin "http://localhost:8085/bamboo/rest/api/latest/result/PROJ2-STAGETEST-JOB1?buildstate"
  2. One thing to keep in mind is that jobs inside the same stage can possibly run parallel, so if you want to guarantee a specifc running order for your jobs, put them into separate sequential stages.
  3. You can add a script task to the beginning of every job in each stage to check the status of the previous job (from the previous stage) and decide how you want to continue the workflow (to shut down your server or let the execution of the plan continue)
  4. In the last stage you can add a final task to shut down your server as all the previous stages were successful.

Please let me know if you have any further questions or concerns.


հաճելիա, հաճելիա

I found these in version 6.9, but not documented anywhere.

${bamboo_buildFailed} for build plan
${bamboo_jobFailed} for deploy plan

Their values are either 'true' or 'false'.  You can catch this status in 'final-tasks' which makes clean up or notifications much easier.

Let me just summarise that with 1 word: GREAT!

For the deployment the jobFailed works perfectly on 7.1.3, although it is only present in a script task, not in an ssh-task...

An approach that I use that seems to works is to create a tracking file.

Step 1: create a tracking file with a starting value in the contents.
Step 2: executes other build tasks.
Step 3: change the value of the tracking file.

In Final Task 
Step 4: check content of tracking file and act accordingly.  

If the job fails before step 3 then step 3 is never ran. Step 4 is alway ran because it is a Final Task at which point you can check the tracking file to see how far you job got.

0 votes

The current job status is available to custom Java tasks through the TaskContext passed to the Task's execute method. For example:

public TaskResult execute(TaskContext taskContext) {
    CurrentBuildResult currentBuildResult = taskContext.getBuildContext().getBuildResult();
    currentBuildResult.getBuildState(); // indicates the status of the whole job
    currentBuildResult.getTaskResults(); // indicates which tasks have passed or failed or not yet run within the current job

As far as I can tell, this same information is not automatically available to simple shell script tasks. If you don't want to maintain a Java plugin for Bamboo, you would have to fall back to using a temporary file within the build (created by the last task run in a successful run) to indicate build status, and add a check for this file in the final script task.


I would like to know if there is a way to prevent a code push on a Bitbucket branch if Bamboo is currently building a job from that branch. So a couple of things I am trying to figure out are:

(1) How does one figure out is a Bamboo job is in progress using HTTP or othe rmeans? Bamboo's "buildstate" variable does not seem to have a value, like, "running" for in-progress jobs.

(2) Does Bitbucket have a pre-commit hook that can then check for Bamboo's "buildstate" variable on a branch before accepting a code push into that branch?



Now I see, but that does not fit into our workflow.

We have some custom scripts with different behaviour that depends on build result: is it Successfully finished or Failed.

I can run those scripts if Build finished successfully. But, as I see, there is no way to run scripts if Build failed:
a) within the same Stage: because Job's build state is Unknown until Job is finished
b) within another Stage: because Stage 2 will not start if Stage 1 fails

I was able to get what I want with Pre/Post Build Command Plugin. We just wanted to get such behaviour out-of-the-box.

Anyway thanks for your suggestions!

0 votes
ArmenA Rising Star Jul 29, 2013


I didn't use it from Bamboo; I used it from a different browser tab just to show you the different values of the state component. You can use a command like 'wget' or 'curl' with a similar URL to get the results from a script.


Thanks Armen,

could you advise where have you called this REST API requset: http://localhost:8085/rest/api/latest/result/PROJ-PLAN-JOB1/7 ?

From the Final Task of Job 1 or from another Job of Stage 1?

0 votes
ArmenA Rising Star Jul 28, 2013

Hi Oleksandr,

You are right - Stage 1 must finish before Stage 2 can start. I tried to use this type of REST calls to get the status of Job1 in Stage 1 and Job2 in Stage 2:


When the first job was done, the status information was as:

<result onceOff="false" id="1474588" number="7" lifeCycleState="Finished" state="Successful" key="PROJ-PLAN-JOB1-7" expand="changes,testResults,metadata,logEntries,plan,vcsRevisions,artifacts,comments,labels,jiraIssues">

When Job2 hasn't started yet, this was the result:

<result onceOff="false" id="1474589" number="7" lifeCycleState="Pending" state="Unknown" key="PROJ-PLAN-JOB2-7" expand="changes,metadata,logEntries,plan,vcsRevisions,jiraIssues">

Does this answer your question? Yuou can experiment with the REST API and see what Bamboo shows in different scenarios.


Hi Armen,

please explain how we can run a Job with such REST API call from Stage 2, if Stage 1 already failed.

As I understand, Stage 2 will not start if Stage 1 fail.

I'm trying to find a way, how to check build status (Success/Fail) within one Stage. But it seems, that current REST API do not provide Job status information unitl this Job is finished.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events