I am trying to find an example that can show how to use azure cli to update pre deployment conditions on a azure devops pipeline such as select/unselect one of the check boxes below
Asked
Active
Viewed 190 times
1 Answers
0
I don't believe the az devops
extension supports the UI style pipelines and it likely won't, given that multi-stage-YAML-pipelines are the current future. The REST API for this change is pretty simple though and you can use powershell to fix this quite easily.
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;
And the open source vsteam
tool has an option to get and update a Release Definition as well:
PS C:\> $b = Get-VSTeamReleaseDefinition -ProjectName Demo -Id 23 -Raw
PS C:\> $b.variables.subscriptionId.value = 'Some New Value'
PS C:\> $body = $b | ConvertTo-Json -Depth 100
PS C:\> Update-VSTeamReleaseDefinition -ProjectName Demo -ReleaseDefinition $body
To get the release ID, you can query all releases in a project. And a similar call exists to query all projects in a account.
PS C:\> Get-VSTeamReleaseDefinition -ProjectName demo

jessehouwing
- 106,458
- 22
- 256
- 341
-
Thank you so much. I am trying to get a list of release definitions in the project and update the pre conditions on a preferred stage. In your code i need to know release id before hand. Is it possible to iterate over a result set and get the release id dynamically? Please advise. Can you provide a sample code for that? Thanks in advance. – ykm Jan 09 '20 at 16:02
-
Updated the answer. – jessehouwing Jan 09 '20 at 16:12