Hello,
I am attempting to use the Bamboo REST API from within Bamboo to check on the state of a previous job. However, I'm unable to get this to work.
According to the documentation for the version we are using (6.9.1), I can use the /result API - https://docs.atlassian.com/atlassian-bamboo/REST/6.9.1/#d2e5392
/result/{projectKey}-{buildKey}/{buildNumber : ([0-9]+)|(latest)}
Using the script below, I'm sending a GET request to a URL similar to (where the build number changes each time) -
https://my.bamboo.url/rest/api/latest/result/LP-RBIT2-RIT/8?buildstate&os_authType=basic
However, this is failing with a 401 error. The user that is authorising the REST call has admin privileges for the plan in question, so I'm not sure why this would be. I've check also to ensure that the user is active (with 0 of 3 failed captcha attempts).
You do not have sufficient read permissions
I've reviewed the documentation for using the Bamboo REST APIs, and I can see any mention of further Bamboo configuration being required to enable users to use the REST API. I have also attempted the REST call in a browser, and while I was asked to log in, the browser then receives no response at all (the network tab on F12 is empty).
My script
$bambooUrl = "https://my.bamboo.url"
### Get the state of the job that just ran the tests by using the Bamboo REST API.
$jobStateUserPassPair = "$env:bamboo_apiUsername:$env:bamboo_apiPassword"
$jobStateEncodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($jobStateUserPassPair))
$jobStateBasicAuthHeader = @{ "Authorization" = ("Basic {0}" -f $jobStateEncodedCreds) }
$jobStateUri = "{0}/rest/api/latest/result/{1}/{2}?os_authType=basic" -f $bambooUrl, $env:bamboo_buildKey, $env:bamboo_buildNumber
$jobState = Invoke-RestMethod -Method Get -Uri $jobStateUri