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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Trigger deployment project after another deployment project done

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

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 Oct 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

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 Oct 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

@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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 7.1 is here and is packed with value!

I'm happy to announce that Bamboo 7.1 has been released and it’s overflowing with awesome new features. Top-voted issues First and foremost, a bunch of JAC top voted issues has been delivered - y...

675 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you