How to call a REST API in Bamboo Data Center using Powershell

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.

You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.

We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!

This article explains about how to call a REST API using Powershell script task in Bamboo.

Environment

The below script has been tested on Bamboo 9.6.4 but the solution is applicable for any other supported version.

Solution

In the below REST API we are trying to update the Project Variable named testVariable of Bamboo project named SCRIP to hardcoded value of 2. This is just an example to show how to use the Powershell to call a REST API using a script task in Bamboo. If you wish to use other REST API's please change the Input values accordingly.

The detailed REST API is available at REST API to update Project variable

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 # Define the credentials $username = $env:bamboo_AdminUser $password = $env:bamboo_AdminPassword # Encode the credentials $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($password)")) # Enforce TLS 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Define Bamboo server URL and Project Key and the Variables which needs to be updated $BambooServer = "https://bamboo-url" $ProjectKey = "SCRIP" $VariableName = "testVariable" # Encode credentials to Base64 $pair = "$($username):$($password)" $encodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($pair)) # Create the authorization header $headers = @{ Authorization = "Basic $encodedCredentials" } $CurrentValue = $env:bamboo_testVariable # Updated value of the variable $NewValue = 2 # Update the project variable with the new value $Body = @{ name = $VariableName value = $NewValue } | ConvertTo-Json # Add Content-Type header for PUT request $headers["Content-Type"] = "application/json" $response = Invoke-RestMethod -Uri "$BambooServer/rest/api/latest/project/$ProjectKey/variable/" -Headers $headers -Method PUT -Body $Body

Inputs which will require a change

  • username, password - In the above example we are storing this into two variables AdminUser, AdminPassword

  • BambooServer - Please replace this with your Bamboo URL

  • ProjectKey - Please replace this with your Project Key

  • VariableName - Replace this with the variable which you wish to update

  • NewValue - Replace this with the new value of the variable

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.