Hello,
I would like to call the github API at the end of the build in order to tell him if the build was successfull or not.
I've created a final task for this but I can't find a bamboo variable who contains the build state.
Could you help me?
Thanks :)
Hélène
Okay so I found the perfect variable (undocumented) : `bamboo_jobFailed` :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Hélène_Droal this is going to save me a headache with the API!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can someone please share the api, it would be helpful for me.
Iam searching it for past week couldn't able to get the proper one.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Github Commit Status API:
https://docs.github.com/en/rest/commits/statuses#create-a-commit-status
Script Task in Bamboo:
REPO="repo-owner/my-repo-name"
if [[ "$bamboo_jobFailed" == "false" ]]
then
STATE=success
else
STATE=failure
fi
DATA="{\"state\":\"$STATE\",\"target_url\":\"$bamboo_buildResultsUrl\",\"description\":\"Bamboo build succeeded!\",\"context\":\"default\"}"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $bamboo_github_token"\
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$REPO/statuses/$bamboo_repository_revision_number" \
-d "$DATA"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is not working anymore -
${bamboo_jobFailed}
Is there any other way we can get the build status in the script task?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
looks like there was a syntax update to reference the variable, example script
${bamboo_jobFailed} instead of $bamboo_jobFailed
#!/usr/bin/env bash
## bamboo does not catch some script failures unless this flag is set
set -e
TASK="CHECK BUILD STATUS"
echo ================== START $TASK ==================
## bamboo_jobFailed is a boolean
BUILD_STATUS=${bamboo_jobFailed}
echo "BUILD_STATUS: $BUILD_STATUS"
if [[ "$BUILD_STATUS" == "true" ]]
then
echo "the build has failed"
else
echo "the build is passing"
fi
echo =================== END $TASK ===================
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey!
Do you mind me asking how accessing this variable works? I cannot seem to be able to call it in my script, as if it doesn't exist?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you running the script in a
Final Tasks
so the script always runs, even if the build fails
Here is how I set it up
(Scripts is the task type)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey!
My bad, I did not read the top of the script properly.... I think it works like a charm now!
This will always grab the status of the current job only right? I don't need to bother with passing the jobs build number etc?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yep current job
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to use the same, but in powershell, but this variable doesn't return any value. I am also using it in the Final Task as mentioned in the above note.
I mean it returns a null value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have not used PowerShell but a quick google looks like there is a Syntax change
BUILD_STATUS=$Env:
bamboo_jobFailed
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.
I am trying to get the status of each step or task available in the build plan. Will that be possible? (I tried the $lastexitcode, but it won't work)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bamboo already does this, kinda. You can assume the task was successful if bamboo continues the process, else if it fails, bamboo will log the issue and from their you can determine.
But here is an idea, not tested
#!/usr/bin/env bash
## bamboo does not catch some script failures unless this flag is set
set -e
TASK_STATUS="STARTED"
echo "TASK_STATUS: $TASK_STATUS"
if [task executes successfully]
then
...
TASK_STATUS="SUCCESS"
echo "TASK_STATUS: $TASK_STATUS"
else
TASK_STATUS="FAILED
echo "TASK_STATUS: $TASK_STATUS"
fi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, its true. But I am trying to check the status of a previous task in a script task, like if the previous task passed or was it disabled. Is that possible?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
not to my knowledge, you could try to use inject variables https://confluence.atlassian.com/bamboo/configuring-a-variables-task-687213475.html
example:
NOTE: this is not 100%, just trying to think outside the box
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.
I would suggest to install this plugin: https://github.com/HackAttack/bamboo-github-status
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.