Update variables while creating release using octopus api

HI Team,

I’m creating deployment using octopus api.
api :
“ReleaseId”: “Releases-id”,
“EnvironmentId”: “Environments-id”,
“ChannelId”: “Channels-id”,
“SkipActions”: [""],
“TenantId” : “Tenants-id”
Is there a way to update variables as well while deploying through api??
thanks in advance

Hi @chandramouli429,

Thanks for getting in touch!

Are you able to provide some more details for the scenario that requires variables to be updated prior to deployment?

The reason I ask is that variables are snapshotted when a release is created, so to amend these before a deployment would require a script to perform the change, and then a refresh of the release variable snapshot.
This isn’t overly recommended though, as the idea of the snapshot is to retain consistency as the release is promoted through each environment. The risk being that you could successfully deploy to your first environment, then change variables and update the snapshot and then the next deploy could fail and you have no easy way to re-deploy.

If the variables you’re wanting to change are ones that only need to exist during a deployment, then a better option would be to use output variables. This would allow you to generate variables using a process step at the beginning of a deployment and then use them in later steps without any additional API calls required.

I look forward to hearing from you.


HI Paul,

Thanks for your quick response.

let’s consider this scenario, where we create a release in Dev environment and we are propagating the same release to test environment. we have to change some settings which are stored in octopus variables for test environment , after the release is created in Dev. if i don’t do update variables the test environment will have old values. In such cases we need to do update variables so the changes reflect.

we are already doing the same with octo.exe.
Octo.exe deploy-release --project="$project" --server=$OctopusURL --ApiKey=$API_Key_Common --channel="$channel" --deployto="$env" --version="$version" --force --tenant=$labs --updateVariables

now i’m trying to achieve the same with api.

Ok, so this would be for fairly rare situations where things like account credentials have been updated rather than something that is being run for every single deployment?

In that case, we have a repository of sample API scripts here: https://github.com/OctopusDeploy/OctopusDeploy-Api

Specific scripts that would be useful starting points for you would be this one for updating a project variable: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/Octopus.Client/PowerShell/Variables/UpdateVariableInProject.ps1

And this one for refreshing the release variable snapshot: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/REST/PowerShell/Releases/Release_UpdateVariables.ps1


Thanks Paul,

let me check and get back to you on this.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.