i have 10 deployment projects. is it possible to trigger all 10 deployment projects without manually trigger each one at a time?
i end up using powershell to call REST Api.
below is my code if you are interested:
$username = "bambooUserName"
$password = "bambooPassword"
$deployEnv = "PRODUCTION"
function Get-Data([string]$httpMethod, [string]$url) {
$credPair = "$($username):$($password)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
$headers = @{ Authorization = "Basic $encodedCredentials" }
$responseData = Invoke-WebRequest -Uri $url -Method $httpMethod -Headers $headers -ContentType 'application/json; charset=utf-8' -UseBasicParsing
return $responseData
}
function TriggerLatestDeployByProjectId([string]$projectId){
$data = Get-Data -httpMethod Get -url http://localhost:9087/bamboo/rest/api/latest/deploy/project/$projectId.json
$dataToDict = $data | ConvertFrom-Json
$envId = ""
for ($i=0; $i -lt $dataToDict.environments.length; $i++) {
$env = $dataToDict.environments[$i]
If ($env.name -eq $deployEnv)
{
$envId = $env.id
}
}
if ($envId)
{
$releaseId = ""
$data = Get-Data -httpMethod Get -url http://localhost:9087/bamboo/rest/api/latest/deploy/project/$projectId/versions.json
$dataToDict = $data | ConvertFrom-Json
$releaseId = $dataToDict.versions[0].id
if ($releaseId)
{
$data = Get-Data -httpMethod POST -url "http://localhost:9087/bamboo/rest/api/latest/queue/deployment/?environmentId=$($envId)&versionId=$($releaseId)"
$dataToDict = $data | ConvertFrom-Json
return "Sucess: resultId= $($dataToDict.deploymentResultId)"
}
else
{
return "Error: $($projectId) Missing releaseId"
}
}
else
{
return "Error: $($projectId) Missing EnvId"
}
}
function DeployAll()
{
$data = Get-Data -httpMethod Get -url http://localhost:9087/bamboo/rest/api/latest/deploy/project/all.json
$dataToDict = $data | ConvertFrom-Json
for ($i=0; $i -lt $dataToDict.length; $i++) {
$currProject = $dataToDict[$i]
$deployResultId = TriggerLatestDeployByProjectId -projectId $currProject.id
"Result:$deployResultId $($currProject.name) - $($currProject.id)"
}
}
DeployAll
Hi @Sai Yu,
Sorry I shouldn't have assumed that you were trying to deploy environments from the same project. In this case I think the only way you can accomplish this is to use a script task at the end of "project A environment A1" that uses an API call to trigger "project B enviroment B1".
You can see more about how to do that here:
https://developer.atlassian.com/server/bamboo/rest-api-deployment-triggers-for-bamboo/
I hope that helps!
-Jimmy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was looking at the Rest Api trigger deploy too. But the problem i am facing is how to get the latest versionId?
my build plan needs to do all these
curl -X POST 'http://localhost:9087/bamboo/rest/api/latest/queue/deployment/?environmentId=7536641&versionId=28803073'
thanks
Sai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks @Jimmy Seddon for the quick reply.
The "after successful deployment" trigger only allow me to select deployment within the project. i need to be able to trigger different deployment project.
what i need to do is "project A environment A1" trigger deploy after successfully deployed "project B enviroment B1".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Sai Yu
Welcome to the Community!
Yes you can do this, what you will need to do is on each environment you wish to deploy automatically. Edit the environment, and select triggers:
Then you will want to click the add trigger button and select what type of trigger you would like to execute:
In the example above I'm using the successful completion of another deployment environment, but there are some other options as well. This will automatically trigger the deployment of this environment when the trigger conditions are met. You can use this to setup multiple environments the same way so they will all automatically trigger under the same conditions.
I hope that helps!
-Jimmy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.