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

Trigger deployment project after another deployment project done

Sai Yu October 24, 2019

i have 10 deployment projects. is it possible to trigger all 10 deployment projects without manually trigger each one at a time?

4 answers

1 accepted

0 votes
Answer accepted
Sai Yu November 15, 2019

i end up using powershell to call REST Api.

  1. loop all deployment plans
  2. pickup all project with name "Production"
  3. get the latest release id (first one return) from each project
  4. trigger deploy plans using 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

0 votes
Jimmy Seddon
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 28, 2019

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

Sai Yu October 28, 2019

@Jimmy Seddon 

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

  1. get the latest versionId by projectID **curl rest/api/latest/deploy/project/7405569/versions'
  2. save it as variable (how to read response and how to save it as variable to use on the next step)
  3. use it on the curl command? (call another Rest Api using variable)

 

curl -X POST 'http://localhost:9087/bamboo/rest/api/latest/queue/deployment/?environmentId=7536641&versionId=28803073' 

 

thanks

Sai

0 votes
Sai Yu October 25, 2019

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".

0 votes
Jimmy Seddon
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 25, 2019

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:

EditEnvironment.JPG

Then you will want to click the add trigger button and select what type of trigger you would like to execute:

AddTriggers.JPG

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events