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

Trigger or start a new build on a bamboo plan using rest api from a powershell script

Suguna Tejaswini Nandakumara November 1, 2023

In order to do the trigger I am using the below powershell commands(Also I don't want to use the username password for auth, is there any other way to to that? may be using a PAT or something):

 

$url = "https://<host>/rest/api/latest/queue/<ProjectKey>-<BuildKey>"
$header = @{
"Content-Type"="application/json"
}
$body = @{
"Authorization"="Bearer <Key>"
} | ConvertTo-Json


Invoke-RestMethod -Uri ([Uri]$url) -Method Post -Headers $header -body $body

 

But I keep getting the below error:

Invoke-RestMethod : Unable to connect to the remote server..

 

What am I missing in the above line..or is there any other way to achieve this?

1 answer

1 vote
Shashank Kumar
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 1, 2023

Hello Suguna,

Welcome to Atlassian community.

You can use the use the below 2 links to get more information about this, instead of using userid password you can generate PAT tokens. 

1. https://docs.atlassian.com/atlassian-bamboo/REST/8.2.5/#d2e5904

2. https://developer.atlassian.com/server/bamboo/using-the-bamboo-rest-apis/

Sample example ( replace the appropriate values accordingly )

curl -H "Authorization: Bearer NDc4NDkyNDg3ODE3OstHYSeYC1UgXqRacSqvUbookcZk" POST http://localhost:8085/rest/api/latest/queue/PROJECTKEY-PLANKEY

Regards,

Shashank Kumar

Suguna Tejaswini Nandakumara March 20, 2024

Thank you for the details.

I tried doing below, by adding a powershell script task in a build plan.

$token = "<PAT>"
$headers = @{
Authorization="Bearer $token"
}
Invoke-RestMethod -Method Post -Headers $headers -Uri "http://localhost:8085/rest/api/latest/queue/<PROJECTKEY-PLANKEY>"

I still get the error as below:

Invoke-RestMethod : Unable to connect to the remote server

Shashank Kumar
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 20, 2024

Hello Suguna,

I was able to trigger a REST API with the exact same configurations, example below

$token = "acd"
$headers = @{
Authorization="Bearer $token"
}
Invoke-RestMethod -Method Post -Headers $headers -Uri "http://localhost:8085/rest/api/latest/queue/BAM-BOO"


I think the error which are getting  Invoke-RestMethod : Unable to connect to the remote server , i think localhost is not being able to resolve by the agent where you are running the builds.

Are you running this on a local agent or a remote agent and can you see if the URL you have put for your Bamboo Instance is correct?

Similar question is explained here >  https://stackoverflow.com/questions/38830912/powershell-invoke-restmethod-unable-to-connect-to-the-remote-server

Regards,

Shashank Kumar

Suguna Tejaswini Nandakumara March 21, 2024

Hi,

Yes the URL is correct. May be its because of the authentication issues.

I will look into the link you have added.

Thanks and regards,

Tejaswini N.S

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events