Skip to content

Instantly share code, notes, and snippets.

@DexterPOSH
Last active December 12, 2023 20:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DexterPOSH/2ebca9e55a05a7f2bce3bf83f4b56056 to your computer and use it in GitHub Desktop.
Save DexterPOSH/2ebca9e55a05a7f2bce3bf83f4b56056 to your computer and use it in GitHub Desktop.
This PowerShell script lists out how to use Az CLI's DevOps extension to walk through the release definitions in a project and check for a specific taskId.
# Set the PAT as an Environment variable, put this in your profile.
# I only use the CLI for read operations so make sure you grant the PAT only that access
$env:AZURE_DEVOPS_EXT_PAT = "<Insert PAT Token here>"
# configure the defaults for the Az DevOps extension for Az CLI to use
az devops configure --defaults organization=https://dev.azure.com/dexterposh project=Test.Project
# see the configured defaults
az devops configure --list
# fetch all the release pipelines metadata for the project
$ProjectName = 'Test.Project'
# Explore one of the Task Release definition to fetch the taskID
# Create or reference an existing Release definition containing the task you want to look for
# In my case, I created a new pipeline only with AzSK_SVTs task
$dummyReleaseDef = az pipelines release definition show --name test-pipeline-with-azsk | ConvertFrom-Json
# Now check the task Id in the
$dummyReleaseDef.environments.deployphases.workflowtasks | Select-Object -Property name, taskId, enabled
# From the above I derived that the taskID for AzSK_SVTs is the below
$TaskID = "c016cc55-9914-4a9c-b9df-f24d6f9a40f6"
# make a note here that we query the release definition list
$ReleaseDefs = az pipelines release definition list --project $ProjectName | ConvertFrom-Json
# Generate output
$AzSKTaskReleaseAudit = foreach ($releaseDef in $ReleaseDefs)
{
# fetch the full Release definition Object for the Release def
$releaseDefObject = az pipelines release definition show --id $releaseDef.Id | ConvertFrom-Json
# Filter the workflow tasks across environments & deploy phases to see the task is present
# Note how I use taskID instead of task name
$AzSKTaskFound = $releaseDefObject.environments.deployphases.workflowtasks |
Where-Object -Property taskId -eq $TaskID
# generate the Output
if ($AzSKTaskFound)
{
[PSCustomObject]@{
ReleaseName = $releaseDefObject.Name
ReleaseId = $releaseDefObject.Id
AzSKTask = $true
AzSKTaskEnabled = @($AzSKTaskFound.Enabled)
}
}
else
{
[PSCustomObject]@{
ReleaseName = $releaseDefObject.Name
ReleaseId = $releaseDefObject.Id
AzSKTask = $false
AzSKTaskEnabled = @($false)
}
}
}
# Analyze the resuls
$AzSKTaskReleaseAudit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment