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

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

Create release via API via powershell

I am trying to achieve similar result as in https://community.atlassian.com/t5/Bamboo-questions/API-Call-to-Create-Release/qaq-p/773999

My Bamboo version is 6.9.2 build 60911.
Here is the code:

First, I am getting all deployment environments attached to build plan via request:

Invoke-WebRequest -uri $($baseUrl + "/rest/api/latest/deploy/project/forPlan?planKey=$buildPlanKey") -Headers $authHeader -UseBasicParsing -ErrorAction Stop -Verbose;

Then, I select my deployment project id out of results to variable $deploymentId and check, if there is a release with my name present

Invoke-WebRequest -uri $($baseUrl + "/rest/api/latest/deploy/project/$deploymentId/versions") -Headers $authHeader -UseBasicParsing -ErrorAction Stop -Verbose;

If release with my name is not present - I wish to create it with following code

        $releaseData = @{            
planResultKey = $buildPlanKey            
name          = $BambooReleaseName        
};        


$json = $releaseData | ConvertTo-Json;

try {            
Invoke-RestMethod -Method Post -Body $json -Uri $($url + "/rest/api/latest/deploy/project/$deploymentId/version.json") -Headers $headers -ContentType "application/json" -Verbose;        
}        
catch 
{            
$result = $_.Exception.Response.GetResponseStream();
$reader = New-Object System.IO.StreamReader($result);
$reader.BaseStream.Position = 0;
$reader.DiscardBufferedData();
$reader.ReadToEnd(); 
}

But, at the end I get this:

{"errors":["Please provide a valid plan key"],"fieldErrors":{}}

However, as you can see by previous code - I am using valid plan key to retrieve deployment project. Why this error pops up? What am I doing wrong?

 

1 answer

1 accepted

0 votes
Answer accepted

I found the reason - in json 

$releaseData = @{            
planResultKey = $buildPlanKey            
name          = $BambooReleaseName        
};   

I need to pass valid build result, not build plan

So it should be 

$releaseData = @{            
planResultKey = ${bamboo.buildResultKey}            
name          = $BambooReleaseName        
};   

Suggest an answer

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

Bamboo Data Center is here!

G’day Bamboo customers, The wait is over! Bamboo Data Center edition you have been asking for is finally here! This self-managed enterprise offering of Bamboo has the resilience, reliability, and s...

501 views 1 17
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