Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new pipeline to create package work item #7322

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 64 additions & 32 deletions eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function BuildHashKey()
}

$parentWorkItems = @{}
function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand = $false, $ignoreReleasePlannerTests = $true)
function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand = $false, $ignoreReleasePlannerTests = $true, $tag = $null)
{
$key = BuildHashKey $serviceName $packageDisplayName
if ($key -and $parentWorkItems.ContainsKey($key)) {
Expand All @@ -154,6 +154,9 @@ function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand =
else {
$serviceCondition = "[ServiceName] <> ''"
}
if ($tag) {
maririos marked this conversation as resolved.
Show resolved Hide resolved
$serviceCondition += " AND [Tags] CONTAINS '${tag}'"
}
if($ignoreReleasePlannerTests){
$serviceCondition += " AND [Tags] NOT CONTAINS 'Release Planner App Test'"
}
Expand Down Expand Up @@ -185,10 +188,10 @@ function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand =
$packageWorkItems = @{}
$packageWorkItemWithoutKeyFields = @{}

function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true, $ignoreReleasePlannerTests = $true, $tag = $null)
{
# Cache all the versions of this package and language work items
$null = FindPackageWorkItem $lang $packageName -includeClosed $true -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$null = FindPackageWorkItem $lang $packageName -includeClosed $true -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
praveenkuttappan marked this conversation as resolved.
Show resolved Hide resolved

$latestWI = $null
foreach ($wi in $packageWorkItems.Values)
Expand All @@ -208,7 +211,7 @@ function FindLatestPackageWorkItem($lang, $packageName, $outputCommand = $true,
return $latestWI
}

function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $true, $includeClosed = $false, $ignoreReleasePlannerTests = $true)
function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $true, $includeClosed = $false, $ignoreReleasePlannerTests = $true, $tag = $null)
{
$key = BuildHashKeyNoNull $lang $packageName $version
if ($key -and $packageWorkItems.ContainsKey($key)) {
Expand Down Expand Up @@ -254,6 +257,9 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
if ($version) {
$query += " AND [PackageVersionMajorMinor] = '${version}'"
}
if ($tag) {
$query += " AND [Tags] CONTAINS '${tag}'"
}
if($ignoreReleasePlannerTests){
$query += " AND [Tags] NOT CONTAINS 'Release Planner App Test'"
}
Expand Down Expand Up @@ -331,7 +337,8 @@ function CreateWorkItemParent($id, $parentId, $oldParentId, $outputCommand = $tr

Invoke-AzBoardsCmd "work-item relation add" $parameters $outputCommand | Out-Null
}
function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo, $parentId, $outputCommand = $true)

function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo, $parentId, $relatedId = $null, $outputCommand = $true, $tag = $null)
{
$parameters = $ReleaseDevOpsCommonParametersWithProject
$parameters += "--title", "`"${title}`""
Expand All @@ -341,25 +348,51 @@ function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo,
if ($assignedTo) {
$parameters += "--assigned-to", "`"${assignedTo}`""
}
if ($tag)
{
if ($fields)
{
$fields += "`"System.Tags=${tag}`""
}
else
{
$parameters += "--fields"
$parameters += "`"System.Tags=${tag}`""
}
}
if ($fields) {
$parameters += "--fields"
$parameters += $fields
}

Write-Host "Creating work item"
$workItem = Invoke-AzBoardsCmd "work-item create" $parameters $outputCommand

if ($parentId) {
$parameters = $ReleaseDevOpsCommonParameters
$parameters += "--id", $workItem.id
$parameters += "--relation-type", "parent"
$parameters += "--target-id", $parentId

Invoke-AzBoardsCmd "work-item relation add" $parameters $outputCommand | Out-Null
Write-Host $workItem
$workItemId = $workItem.id
Write-Host "Created work item [$workItemId]."
if ($parentId)
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
{
CreateWorkItemRelation $workItemId $parentId "parent" $outputCommand
}

# Add a work item as related if given.
if ($relatedId)
{
CreateWorkItemRelation $workItemId $relatedId "Related" $outputCommand
}

return $workItem
}

function CreateWorkItemRelation($id, $relatedId, $relationType, $outputCommand = $true)
{
$parameters = $ReleaseDevOpsCommonParameters
$parameters += "--id", $id
$parameters += "--relation-type", $relationType
$parameters += "--target-id", $relatedId
Write-Host "Updating work item [$relatedId] as [$relationType] of [$id]."
Invoke-AzBoardsCmd "work-item relation add" $parameters $outputCommand | Out-Null
}

function UpdateWorkItem($id, $fields, $title, $state, $assignedTo, $outputCommand = $true)
{
$parameters = $ReleaseDevOpsCommonParameters
Expand Down Expand Up @@ -387,12 +420,12 @@ function UpdatePackageWorkItemReleaseState($id, $state, $releaseType, $outputCom
return UpdateWorkItem -id $id -state $state -fields $fields -outputCommand $outputCommand
}

function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPrompt = $false, $outputCommand = $false)
function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPrompt = $false, $outputCommand = $false, $relatedId = $null, $tag= $null, $ignoreReleasePlannerTests = $true)
{
$workItem = FindPackageWorkItem -lang $lang -packageName $pkg.Package -version $verMajorMinor -includeClosed $true -outputCommand $outputCommand
$workItem = FindPackageWorkItem -lang $lang -packageName $pkg.Package -version $verMajorMinor -includeClosed $true -outputCommand $outputCommand -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests

if (!$workItem) {
$latestVersionItem = FindLatestPackageWorkItem -lang $lang -packageName $pkg.Package -outputCommand $outputCommand
$latestVersionItem = FindLatestPackageWorkItem -lang $lang -packageName $pkg.Package -outputCommand $outputCommand -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$assignedTo = "me"
$extraFields = @()
if ($latestVersionItem) {
Expand Down Expand Up @@ -428,15 +461,13 @@ function FindOrCreateClonePackageWorkItem($lang, $pkg, $verMajorMinor, $allowPro
$packageInfo.ServiceName = $readInput
}
}


$workItem = CreateOrUpdatePackageWorkItem $lang $pkg $verMajorMinor -existingItem $null -assignedTo $assignedTo -extraFields $extraFields -outputCommand $outputCommand
$workItem = CreateOrUpdatePackageWorkItem $lang $pkg $verMajorMinor -existingItem $null -assignedTo $assignedTo -extraFields $extraFields -outputCommand $outputCommand -relatedId $relatedId -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
}

return $workItem
}

function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingItem, $assignedTo = $null, $extraFields = $null, $outputCommand = $true)
function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingItem, $assignedTo = $null, $extraFields = $null, $outputCommand = $true, $relatedId = $null, $tag = $null, $ignoreReleasePlannerTests = $true)
{
if (!$lang -or !$pkg -or !$verMajorMinor) {
Write-Host "Cannot create or update because one of lang, pkg or verMajorMinor aren't set. [$lang|$($pkg.Package)|$verMajorMinor]"
Expand Down Expand Up @@ -495,23 +526,24 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
}
}

$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
UpdateWorkItemParent $existingItem $newParentItem -outputCommand $outputCommand
return $existingItem
}

$parentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
$workItem = CreateWorkItem $title "Package" "Release" "Release" $fields $assignedTo $parentItem.id -outputCommand $outputCommand
$parentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests
Write-Host "Found product work item [$($parentItem.id)]. Creating package work item."
$workItem = CreateWorkItem $title "Package" "Release" "Release" $fields $assignedTo $parentItem.id -outputCommand $outputCommand -relatedId $relatedId -tag $tag
Write-Host "[$($workItem.id)]$lang - $pkgName($verMajorMinor) - Created"
return $workItem
}

function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outputCommand = $true, $ignoreReleasePlannerTests = $true, $tag = $null)
{
$existingItem = FindParentWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$existingItem = FindParentWorkItem $serviceName $packageDisplayName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
if ($existingItem) {
Write-Host "Found existing product work item [$($existingItem.id)]"
$newparentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$newparentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
UpdateWorkItemParent $existingItem $newParentItem
return $existingItem
}
Expand All @@ -520,18 +552,18 @@ function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outp
$fields += "`"PackageDisplayName=${packageDisplayName}`""
$fields += "`"ServiceName=${serviceName}`""
$fields += "`"Custom.EpicType=Product`""
$serviceParentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$workItem = CreateWorkItem $packageDisplayName "Epic" "Release" "Release" $fields $null $serviceParentItem.id
$serviceParentItem = FindOrCreateServiceParent $serviceName -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
$workItem = CreateWorkItem $packageDisplayName "Epic" "Release" "Release" $fields $null $serviceParentItem.id -tag $tag

$localKey = BuildHashKey $serviceName $packageDisplayName
Write-Host "[$($workItem.id)]$localKey - Created Parent"
$parentWorkItems[$localKey] = $workItem
return $workItem
}

function FindOrCreateServiceParent($serviceName, $outputCommand = $true, $ignoreReleasePlannerTests = $true)
function FindOrCreateServiceParent($serviceName, $outputCommand = $true, $ignoreReleasePlannerTests = $true, $tag = $null)
{
$serviceParent = FindParentWorkItem $serviceName -packageDisplayName $null -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests
$serviceParent = FindParentWorkItem $serviceName -packageDisplayName $null -outputCommand $outputCommand -ignoreReleasePlannerTests $ignoreReleasePlannerTests -tag $tag
if ($serviceParent) {
Write-Host "Found existing service work item [$($serviceParent.id)]"
return $serviceParent
Expand All @@ -542,7 +574,7 @@ function FindOrCreateServiceParent($serviceName, $outputCommand = $true, $ignore
$fields += "`"ServiceName=${serviceName}`""
$fields += "`"Custom.EpicType=Service`""
$parentId = $null
$workItem = CreateWorkItem $serviceName "Epic" "Release" "Release" $fields $null $parentId -outputCommand $outputCommand
$workItem = CreateWorkItem $serviceName "Epic" "Release" "Release" $fields $null $parentId -outputCommand $outputCommand -tag $tag

$localKey = BuildHashKey $serviceName
Write-Host "[$($workItem.id)]$localKey - Created service work item"
Expand Down
29 changes: 20 additions & 9 deletions eng/common/scripts/Update-DevOps-Release-WorkItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ param(
[string]$packageRepoPath = "NA",
[string]$packageType = "client",
[string]$packageNewLibrary = "true",
[string]$relatedWorkItemId = $null,
[string]$tag = $null,
[string]$devops_pat = $env:DEVOPS_PAT
)
#Requires -Version 6.0
Expand All @@ -23,25 +25,30 @@ if (!(Get-Command az -ErrorAction SilentlyContinue)) {
exit 1
}

az account show *> $null
if (!$?) {
Write-Host 'Running az login...'
az login *> $null
. (Join-Path $PSScriptRoot SemVer.ps1)
. (Join-Path $PSScriptRoot Helpers DevOps-WorkItem-Helpers.ps1)

if (!$devops_pat) {
az account show *> $null
if (!$?) {
Write-Host 'Running az login...'
az login *> $null
}
}
else {
# Login using PAT
LoginToAzureDevops $devops_pat
}

az extension show -n azure-devops *> $null
if (!$?){
Write-Host 'Installing azure-devops extension'
az extension add --name azure-devops
} else {
# Force update the extension to the latest version if it was already installed
# this is needed to ensure we have the authentication issue fixed from earlier versions
az extension update -n azure-devops *> $null
}

. (Join-Path $PSScriptRoot SemVer.ps1)
. (Join-Path $PSScriptRoot Helpers DevOps-WorkItem-Helpers.ps1)

CheckDevOpsAccess

$parsedNewVersion = [AzureEngSemanticVersion]::new($version)
Expand Down Expand Up @@ -69,8 +76,12 @@ $plannedVersions = @(
Date = $plannedDate
}
)
$ignoreReleasePlannerTests = $true
if ($tag -and $tag.Contains("Release Planner App Test")) {
$ignoreReleasePlannerTests = $false
}

$workItem = FindOrCreateClonePackageWorkItem $language $packageInfo $versionMajorMinor -allowPrompt $true -outputCommand $false
$workItem = FindOrCreateClonePackageWorkItem $language $packageInfo $versionMajorMinor -allowPrompt $true -outputCommand $false -relatedId $relatedWorkItemId -tag $tag -ignoreReleasePlannerTests $ignoreReleasePlannerTests

if (!$workItem) {
Write-Host "Something failed as we don't have a work-item so exiting."
Expand Down
70 changes: 70 additions & 0 deletions eng/pipelines/devops-create-package-workitem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
pool:
name: 'azsdk-pool-mms-ubuntu-2204-general'
vmImage: 'ubuntu-22.04'

parameters:
- name: Language
type: string
default: ''
values:
- .NET
- Java
- Python
- JavaScript
- Go
- C++
- C
- name: ServiceName
displayName: Service Name (Value should be same as service name in Service Tree)
type: string
default: ''
- name: PackageDisplayName
displayName: Package Display Name ( for e.g. Azure Core)
type: string
default: ''
- name: PackageType
type: string
default: ''
values:
- Client
- mgmt
- name: PackageName
displayName: Package Name (e.g. Azure.Core)
type: string
default: ''
- name: PackageVersion
displayName: Package Version (e.g. 1.0.0)
type: string
default: ''
- name: ReleaseDate
displayName: Release Date (Format:MM/DD/YYYY)
type: string
default: ''
- name: RelatedWorkItemId
displayName: Related Work Item ID (Applicable to add release plan work Item as related)
type: string
default: ''
- name: Tag
type: string
default: ''

steps:
- checkout: self


- task: PowerShell@2
displayName: Create Package Work Item
inputs:
pwsh: true
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Update-DevOps-Release-WorkItem.ps1
arguments: >
-language "${{parameters.Language}}"
-serviceName "${{parameters.ServiceName}}"
-packageDisplayName "${{parameters.PackageDisplayName}}"
-packageType "${{parameters.PackageType}}"
-packageName "${{parameters.PackageName}}"
-version "${{parameters.PackageVersion}}"
-plannedDate "${{parameters.ReleaseDate}}"
-relatedWorkItemId ${{parameters.RelatedWorkItemId}}
-tag "${{parameters.Tag}}"
-devops_pat "$(azuresdk-azure-sdk-devops-release-work-item-pat)"