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.
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.
curl -X GET --user admin:admin "http://localhost:8085/bamboo/rest/api/latest/result/PROJ2-STAGETEST-JOB1?buildstate"
Please let me know if you have any further questions or concerns.
Cheers,
Armen
հաճելիա, հաճելիա
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
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?
Thanks,
-Shanti
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oleksandr,
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.
Armen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
http://localhost:8085/rest/api/latest/result/PROJ-PLAN-JOB1/7 http://localhost:8085/rest/api/latest/result/PROJ-PLAN-JOB2/7
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.
Armen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.