I am trying to add a new variable to an existing Devops ReleaseEnvironment and redeploy this existing releaseEnvironment. I'm using Microsoft.VisualStudio.Services.Release.Client version 16.199.0-preview.
var connection = new VssConnection("someUrl", new VssBasicCredential(string.Empty, "somePAT"));
var client = connection.GetClient<ReleaseHttpClient>();
var projectHttpClient = connection.GetClient<ProjectHttpClient>();
var project = await projectHttpClient.GetProject("xxx");
var metadata = new ReleaseEnvironmentUpdateMetadata
{
Status = EnvironmentStatus.InProgress
};
metadata.Variables.Add("someVariable",
new ConfigurationVariableValue()
{
Value = "xxx",
AllowOverride = true,
IsSecret = true
});
await client.UpdateReleaseEnvironmentAsync(metadata, project.Id, 999,999);
However, cause this variable does not exist yet, I'm getting the error: Unhandled exception. Microsoft.VisualStudio.Services.Common.VssServiceException: Variable(s) someVariable do not exist in the release environment at scope: PRD. New variables cannot be added while creating deployment.
However it looks like it's possible to do it via the UI. So I was wondering how I can automate this. Does anyone have an idea?
Thx in advance.
Best regards, JeffVN