How to update release level variables using RM rest APIs?

Recently one of the customer wanted to add a release variable using RM Rest APIs and I shared with him the following code. You can get the PAT token using the instructions mentioned here.

string collectionUri = args[0];
string projectName = args[1];
string patToken = args[2];
int releaseId = int.Parse(args[3]);
VssConnection connection = new VssConnection(new Uri(collectionUri), new VssBasicCredential(“username”, patToken));
ReleaseHttpClient client = connection.GetClient<ReleaseHttpClient>();
var release = client.GetReleaseAsync(projectName, releaseId).Result;
var variableValue = new ConfigurationVariableValue();
variableValue.Value = “bar”;
release.Variables.Add(“foo”, variableValue);
var updatedRelease = client.UpdateReleaseAsync(release, projectName, releaseId).Result;

You can get the complete solution from here.

Enjoy !!

Comments (0)

Skip to main content