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?
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.