@@ -71,7 +71,13 @@ function Invoke-AzBoardsCmd($subCmd, $parameters, $output = $true)
7171 if ($output ) {
7272 Write-Host $azCmdStr
7373 }
74- return Invoke-Expression " $azCmdStr " | ConvertFrom-Json - AsHashTable
74+ $response = Invoke-Expression " $azCmdStr " | ConvertFrom-Json - AsHashtable
75+
76+ if ($LASTEXITCODE -ne 0 ) {
77+ Write-Host " ERROR command failed: $azCmdStr "
78+ }
79+
80+ return $response
7581}
7682
7783function Invoke-Query ($fields , $wiql , $output = $true )
@@ -359,14 +365,26 @@ function CreateWorkItemParent($id, $parentId, $oldParentId, $outputCommand = $tr
359365 Invoke-AzBoardsCmd " work-item relation add" $parameters $outputCommand | Out-Null
360366}
361367
368+ function CheckUser ($user )
369+ {
370+ $azCmdStr = " az devops user show --user ${user} $ ( $ReleaseDevOpsCommonParameters -join ' ' ) "
371+ Invoke-Expression " $azCmdStr " | Out-Null
372+
373+ if ($LASTEXITCODE -ne 0 ) {
374+ return $false
375+ }
376+
377+ return $true
378+ }
379+
362380function CreateWorkItem ($title , $type , $iteration , $area , $fields , $assignedTo , $parentId , $relatedId = $null , $outputCommand = $true , $tag = $null )
363381{
364382 $parameters = $ReleaseDevOpsCommonParametersWithProject
365383 $parameters += " --title" , " `" ${title} `" "
366384 $parameters += " --type" , " `" ${type} `" "
367385 $parameters += " --iteration" , " `" ${iteration} `" "
368386 $parameters += " --area" , " `" ${area} `" "
369- if ($assignedTo ) {
387+ if ($assignedTo -and (CheckUser $assignedTo ) ) {
370388 $parameters += " --assigned-to" , " `" ${assignedTo} `" "
371389 }
372390 if ($tag )
@@ -388,7 +406,6 @@ function CreateWorkItem($title, $type, $iteration, $area, $fields, $assignedTo,
388406
389407 Write-Host " Creating work item"
390408 $workItem = Invoke-AzBoardsCmd " work-item create" $parameters $outputCommand
391- Write-Host $workItem
392409 $workItemId = $workItem.id
393410 Write-Host " Created work item [$workItemId ]."
394411 if ($parentId )
@@ -424,7 +441,7 @@ function UpdateWorkItem($id, $fields, $title, $state, $assignedTo, $outputComman
424441 if ($state ) {
425442 $parameters += " --state" , " `" ${state} `" "
426443 }
427- if ($assignedTo ) {
444+ if ($assignedTo -and (CheckUser $assignedTo ) ) {
428445 $parameters += " --assigned-to" , " `" ${assignedTo} `" "
429446 }
430447 if ($fields ) {
0 commit comments