共用方式為


How to disable a workflow task in a release using rest APIs?

Recently one of the customer wanted to know how to disable a task in a release using the rest APIs and here is the code that I shared with him. You can get the PAT token using the instructions mentioned here.

param (
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $token
)

## Construct a basic auth head using PAT
function BasicAuthHeader()
{
param([string]$authtoken)

$ba = (":{0}" -f $authtoken)
$ba = [System.Text.Encoding]::UTF8.GetBytes($ba)
$ba = [System.Convert]::ToBase64String($ba)
$h = @{Authorization=("Basic{0}" -f $ba);ContentType="application/json"}
return $h
}
$getReleaseUri = "https://myaccount.vsrm.visualstudio.com/VSOnline/_apis/Release/releases/100?api-version=4.0-preview.4"

$h = BasicAuthHeader $token

$release = Invoke-RestMethod -Uri $getReleaseUri -Headers $h -Method Get

# Disable a task in an environment
$release.environments[0].deployPhasesSnapshot[0].workflowTasks[0].enabled = $false;

####****************** update the modified object **************************
$release2 = $release | ConvertTo-Json -Depth 100
$release2 = [Text.Encoding]::UTF8.GetBytes($release2)

$updateReleaseUri = “https://myaccount.vsrm.visualstudio.com/defaultcollection/VSOnline/_apis/release/releases/100`?api-version=4.0-preview.4”
$content2 = Invoke-RestMethod -Uri $updateReleaseUri -Method Put -Headers $h -ContentType “application/json” -Body $release2 -Verbose -Debug

write-host "=========================================================="