Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Task - polling for build result from Jenkins

Andrux51
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 30, 2018

I'm trying to set up a task that will make repeated http requests until I get the result I'm looking for (something like "build finished")

 

I'm using Powershell Invoke-WebRequest to attempt this, but I haven't figured out a way to have my task repeat as needed.

 

Here's the script I'm using. I'd appreciate any help I can get!

$res = Invoke-WebRequest http://jenkins-svrnd-asc:8080/jenkins/job/New%20Ascendon/job/${bamboo.planRepository.branch}/lastBuild/api/json

If ($res.StatusCode -ne 200) {
# build not found
exit 1
}

$data = $res.Content | ConvertFrom-Json

If ($data.building) {
# re-run this task
exit 1
} Else {
If ($data.result -eq 'SUCCESS') {
# go to next step
exit 0
} ElseIf ($data.result -eq 'FAILURE') {
# drop out to failure step
exit 1
} ElseIf ($data.result -eq 'UNSTABLE') {
# drop out to failure step
exit 1
}
}

 

1 answer

0 votes
robhit
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 5, 2018

Hi,

Thanks for your question!

First of all, I am not a Windows PowerShell expert so please excuse me for very generic response. But logically how about using a while loop to continuously look for the result and then based on the found condition set the counter (as true or false) to exit the loop?

Let me know if it makes sense, or I will try to implement it in Bash.

Thanks,

Robhit

Suggest an answer

Log in or Sign up to answer