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

Need start and end time of bamboo pipeline from rest api

Madhu March 24, 2023

Hi All,

 

Can any one help me how to get start and end date time of bamboo pipeline from rest api.

 

Thanks in Advance!!

1 answer

1 accepted

1 vote
Answer accepted
Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 25, 2023

Hello @Madhu

You can use the /rest/api/latest/result/{projectKey}-{buildKey}-{buildNumber} REST endpoint for that. For example:

# curl -s -H "Accept: application/json" -uuser:pass -X GET 'https://bamboo825.mydomain.net/rest/api/latest/result/ABC-AG-111' | jq '.buildStartedTime, .buildCompletedDate'
"2023-03-24T22:16:21.163+11:00"
"2023-03-24T22:17:36.668+11:00"

Best regards,

Eduardo Alvarenga
Atlassian Support APAC

--please don't forget to Accept the answer if the reply is helpful-- 

Madhu March 27, 2023

Hi Alvarenga,

 

How to pass  ('.buildStartedTime, .buildCompletedDate') these two params in above rest api querystring. for ex: 

https://bamboo.abc.com/rest/api/latest/result/<plankey>?starttime?endtime&buildState=Successful&max-results=1

 

curl command works in linux but i'm hitting rest api from external tool so i want to append buildstarttime and completedtime.

 

Thanks in advance!!

 

Regards,

Madhu

Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2023

Hello @Madhu

Welcome to Atlassian Community!

The /rest/api/latest/result/{projectKey}-{buildKey}-{buildNumber} REST endpoint will not allow you to filter the results by start or end times in the request. For that, you will have to do the filter via the application. For example:

This will check builds for Plan ABC-AG between 2023-03-23 and 2023-03-28.

$ curl -s -H "Accept: application/json" -uuser:pass -X GET 'https://bamboo825.mydomain.net/rest/api/latest/result/ABC-AG?expand=results.result' |
  jq --arg s '2023-03-23T00:00:00' --arg e '2023-03-28T23:59:59' '.results.result[] |
       select(
           (.buildStartedTime   | .[0:19] +"Z" | fromdateiso8601 | todateiso8601 >= ($s | strptime("%Y-%m-%dT%H:%M:%S") | todateiso8601))
       and
           (.buildCompletedTime | .[0:19] +"Z" | fromdateiso8601 | todateiso8601 <= ($e | strptime("%Y-%m-%dT%H:%M:%S") | todateiso8601))
and
(.buildState == "Successful" )
       ) | .key + " " + .buildState + " " + .buildStartedTime + " " + .buildCompletedTime'

Notice above that I'm not using {projectKey}-{buildKey}-{buildNumber}, instead, I'm just using {projectKey}-{buildKey} to scan all builds.

You may optimise the jq syntax or your external tool to format it to include Timezones for example.

Output:

"ABC-AG-111 Successful 2023-03-24T22:16:21.163+11:00 2023-03-24T22:17:36.668+11:00"
"ABC-AG-110 Successful 2023-03-24T12:15:53.610+11:00 2023-03-24T12:17:07.091+11:00"
"ABC-AG-109 Successful 2023-03-24T12:06:56.589+11:00 2023-03-24T12:08:10.878+11:00"
"ABC-AG-108 Successful 2023-03-24T11:57:32.923+11:00 2023-03-24T11:58:46.870+11:00"
"ABC-AG-107 Successful 2023-03-24T11:55:14.940+11:00 2023-03-24T11:56:28.480+11:00"
"ABC-AG-106 Successful 2023-03-24T11:49:14.927+11:00 2023-03-24T11:50:28.578+11:00"
"ABC-AG-105 Successful 2023-03-24T11:11:05.353+11:00 2023-03-24T11:12:20.578+11:00"

Cheers,

Eduardo Alvarenga
Atlassian Support APAC

--please don't forget to Accept the answer if the reply is helpful--

Like Steffen Opel _Utoolity_ likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events