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

Not updating multiple Work Items in the same release #66

Open
jwar-gilson opened this issue May 28, 2020 · 22 comments
Open

Not updating multiple Work Items in the same release #66

jwar-gilson opened this issue May 28, 2020 · 22 comments

Comments

@jwar-gilson
Copy link

jwar-gilson commented May 28, 2020

Can you provide some insight why my WorkItemUpdater is not updating multiple work items but just one every time?

Here are my settings configured:
image

Here is the log in VSTS showing one work item being updated. There were TWO work items in the release:
image

@jwar-gilson
Copy link
Author

Created another Release today that had two related WITs attached. Below is the debug log (minus some sensitive information related to my company/employees (used [BLAH BLAH BLAH])):

Work Items

image

Debug logs

2020-05-29T15:53:38.4913145Z ##[debug]Evaluating: succeeded()
2020-05-29T15:53:38.4914011Z ##[debug]Evaluating succeeded:
2020-05-29T15:53:38.4915063Z ##[debug]=> True
2020-05-29T15:53:38.4915594Z ##[debug]Result: True
2020-05-29T15:53:38.4916143Z ##[section]Starting: WorkItem Updater
2020-05-29T15:53:38.5024779Z ==============================================================================
2020-05-29T15:53:38.5025120Z Task         : WorkItem Updater
2020-05-29T15:53:38.5025422Z Description  : This task adds functionality to update WorkItems during a Build or Release.
2020-05-29T15:53:38.5025741Z Version      : 2.5.797
2020-05-29T15:53:38.5025931Z Author       : Blue Basher
2020-05-29T15:53:38.5026929Z Help         : 
2020-05-29T15:53:38.5027185Z ==============================================================================
2020-05-29T15:53:38.7205577Z ##[debug]agent.TempDirectory=d:\a\_temp
2020-05-29T15:53:38.7238096Z ##[debug]loading inputs and endpoints
2020-05-29T15:53:38.7248568Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2020-05-29T15:53:38.7263417Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2020-05-29T15:53:38.7267135Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2020-05-29T15:53:38.7269968Z ##[debug]loading INPUT_ALLWORKITEMSSINCELASTRELEASE
2020-05-29T15:53:38.7274350Z ##[debug]loading INPUT_ASSIGNEDTO
2020-05-29T15:53:38.7276329Z ##[debug]loading INPUT_BYPASSRULES
2020-05-29T15:53:38.7279812Z ##[debug]loading INPUT_FAILTASKIFNOWORKITEMSAVAILABLE
2020-05-29T15:53:38.7299312Z ##[debug]loading INPUT_LINKBUILD
2020-05-29T15:53:38.7299908Z ##[debug]loading INPUT_UPDATEASSIGNEDTO
2020-05-29T15:53:38.7300343Z ##[debug]loading INPUT_UPDATEASSIGNEDTOWITH
2020-05-29T15:53:38.7300750Z ##[debug]loading INPUT_WORKITEMCURRENTSTATE
2020-05-29T15:53:38.7301136Z ##[debug]loading INPUT_WORKITEMDONE
2020-05-29T15:53:38.7301544Z ##[debug]loading INPUT_WORKITEMKANBANSTATE
2020-05-29T15:53:38.7304116Z ##[debug]loading INPUT_WORKITEMSSOURCE
2020-05-29T15:53:38.7314303Z ##[debug]loading INPUT_WORKITEMTYPE
2020-05-29T15:53:38.7319659Z ##[debug]loading SECRET_AZURE_APP_SERVICE_KUDU_PRODUCTION_PASSWORD
2020-05-29T15:53:38.7326414Z ##[debug]loaded 16
2020-05-29T15:53:38.7350267Z ##[debug]Agent.ProxyUrl=undefined
2020-05-29T15:53:38.7352003Z ##[debug]Agent.CAInfo=undefined
2020-05-29T15:53:38.7352496Z ##[debug]Agent.ClientCert=undefined
2020-05-29T15:53:38.7352898Z ##[debug]Agent.SkipCertValidation=undefined
2020-05-29T15:53:38.9168872Z ##[debug]System.TeamFoundationCollectionUri=https://[BLAH BLAH BLAH.COM]/
2020-05-29T15:53:38.9178872Z ##[debug]SYSTEMVSSCONNECTION auth param AccessToken = ***
2020-05-29T15:53:38.9208207Z ##[debug]Build.BuildId=2797
2020-05-29T15:53:38.9208851Z ##[debug]System.TeamProjectId=[BLAH BLAH BLAH]
2020-05-29T15:53:38.9209331Z ##[debug]Build.RequestedFor=[BLAH BLAH BLAH]
2020-05-29T15:53:38.9213443Z ##[debug]workitemsSource=Build
2020-05-29T15:53:38.9213998Z ##[debug]workitemsSourceQuery=null
2020-05-29T15:53:38.9216450Z ##[debug]allWorkItemsSinceLastRelease=false
2020-05-29T15:53:38.9218841Z ##[debug]workItemType=Bug,User Story
2020-05-29T15:53:38.9219309Z ##[debug]workItemState=null
2020-05-29T15:53:38.9220610Z ##[debug]workItemCurrentState=Active
2020-05-29T15:53:38.9221079Z ##[debug]workItemKanbanLane=null
2020-05-29T15:53:38.9297108Z ##[debug]workItemKanbanState=Test
2020-05-29T15:53:38.9298066Z ##[debug]workItemDone=false
2020-05-29T15:53:38.9298813Z ##[debug]linkBuild=true
2020-05-29T15:53:38.9299658Z ##[debug]updateAssignedTo=Always
2020-05-29T15:53:38.9300284Z ##[debug]updateAssignedToWith=FixedUser
2020-05-29T15:53:38.9300739Z ##[debug]assignedTo=[BLAH BLAH BLAH]
2020-05-29T15:53:38.9301163Z ##[debug]updateFields=null
2020-05-29T15:53:38.9301571Z ##[debug]bypassRules=false
2020-05-29T15:53:38.9302498Z ##[debug]failTaskIfNoWorkItemsAvailable=false
2020-05-29T15:53:38.9303300Z ##[debug]addTags=null
2020-05-29T15:53:38.9306419Z ##[debug]removeTags=null
2020-05-29T15:53:38.9306890Z ##[debug]Release.ReleaseId=682
2020-05-29T15:53:38.9307667Z ##[debug]Release.DefinitionId=2
2020-05-29T15:53:38.9308277Z ##[debug]Release.DefinitionEnvironmentId=2
2020-05-29T15:53:38.9309091Z ##[debug]BuildId 2797
2020-05-29T15:53:38.9309834Z ##[debug]ProjectId [BLAH BLAH BLAH]
2020-05-29T15:53:38.9310255Z ##[debug]ReleaseId 682
2020-05-29T15:53:38.9310625Z ##[debug]DefinitionId 2
2020-05-29T15:53:38.9310992Z ##[debug]DefinitionEnvironmentId 2
2020-05-29T15:53:38.9311414Z ##[debug]requestedFor [BLAH BLAH BLAH]
2020-05-29T15:53:38.9312195Z ##[debug]workitemsSource Build
2020-05-29T15:53:38.9327528Z ##[debug]workitemsSourceQuery null
2020-05-29T15:53:38.9327981Z ##[debug]allWorkItemsSinceLastRelease false
2020-05-29T15:53:38.9328412Z ##[debug]workItemType Bug,User Story
2020-05-29T15:53:38.9328794Z ##[debug]WorkItemState null
2020-05-29T15:53:38.9329187Z ##[debug]workItemCurrentState Active
2020-05-29T15:53:38.9329617Z ##[debug]updateWorkItemKanbanLane null
2020-05-29T15:53:38.9330025Z ##[debug]WorkItemKanbanState Test
2020-05-29T15:53:38.9330416Z ##[debug]WorkItemDone false
2020-05-29T15:53:38.9330802Z ##[debug]updateAssignedTo Always
2020-05-29T15:53:38.9331192Z ##[debug]updateAssignedToWith FixedUser
2020-05-29T15:53:38.9331703Z ##[debug]assignedTo [BLAH BLAH BLAH]
2020-05-29T15:53:38.9332098Z ##[debug]addTags null
2020-05-29T15:53:38.9332469Z ##[debug]updateFields null
2020-05-29T15:53:38.9332842Z ##[debug]removeTags null
2020-05-29T15:53:38.9333210Z ##[debug]bypassRules false
2020-05-29T15:53:38.9333617Z ##[debug]failTaskIfNoWorkItemsAvailable false
2020-05-29T15:53:38.9334032Z ##[debug]Get WorkItemTrackingApi
2020-05-29T15:53:38.9357212Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9357835Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9358267Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9358722Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9359199Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9359616Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9360042Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9360449Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9360872Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9361287Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9361710Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9362161Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9362574Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9362994Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9363406Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:38.9363850Z (node:2548) Warning: Use Cipheriv for counter mode of aes-256-ctr
2020-05-29T15:53:39.1983575Z ##[debug]Get workItemsRefs
2020-05-29T15:53:39.1989193Z Using Build as WorkItem Source
2020-05-29T15:53:39.3905060Z ##[debug]Loop workItemsRefs
2020-05-29T15:53:39.3910558Z ##[debug]Found WorkItemRef: 5056
2020-05-29T15:53:39.6076368Z Found WorkItem: 5056
2020-05-29T15:53:39.6077220Z ##[debug]Using fixed user "[BLAH BLAH BLAH]" as assignedTo.
2020-05-29T15:53:39.6088172Z ##[debug]Updating  WorkItem: 5056
2020-05-29T15:53:39.6088646Z Updating WorkItem 5056
2020-05-29T15:53:39.6091400Z ##[debug]Found KanbanLane: 
2020-05-29T15:53:39.6092734Z ##[debug]Found KanbanColumn: WEF_38DD72CBDD224FAD9E544F9A54C6FFB8_Kanban.Column
2020-05-29T15:53:39.6093526Z ##[debug]Found KanbanColumnDone: WEF_38DD72CBDD224FAD9E544F9A54C6FFB8_Kanban.Column.Done
2020-05-29T15:53:39.6094782Z Patch: /fields/WEF_38DD72CBDD224FAD9E544F9A54C6FFB8_Kanban.Column Test
2020-05-29T15:53:39.6096666Z Linking Build 2797 to WorkItem 5056
2020-05-29T15:53:39.6097350Z Patch: /relations/- [object Object]
2020-05-29T15:53:39.6097724Z Patch: /fields/System.AssignedTo [BLAH BLAH BLAH]
2020-05-29T15:53:39.6098127Z ##[debug]Start UpdateWorkItem
2020-05-29T15:53:40.0544265Z WorkItem 5056 updated
2020-05-29T15:53:40.0545239Z ##[debug]Finished loop workItemsRefs
2020-05-29T15:53:40.0547302Z ##[debug]task result: Succeeded
2020-05-29T15:53:40.0550567Z ##[debug]Processed: ##vso[task.complete result=Succeeded;]
2020-05-29T15:53:40.0640196Z ##[section]Finishing: WorkItem Updater

@jwar-gilson
Copy link
Author

@BlueBasher is this still an active project?

@BlueBasher
Copy link
Owner

Yes it is still active. Currently have very little time though to do any coding on it. Happy to accept any PR though.. ;)

@jwar-gilson
Copy link
Author

@BlueBasher looking at this https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/get%20build%20work%20items%20refs?view=azure-devops-rest-5.1

There is a $top optional parameter and it looks like you already merged this into your latest #65 but I am not seeing it in the settings configurations for the extension. Was there a default of 1 before this was merged? Is this going to get published so we can configure it to see if this solves my issue?

@BlueBasher
Copy link
Owner

You are correct, the Access Token for publishing the extension was expired..
I updated it and the new version should now be available.

@jwar-gilson
Copy link
Author

jwar-gilson commented Jun 22, 2020

@BlueBasher Ran another release today with 4 work items and got the same results here -#66 (comment)

It only updated one work item and the workItemLimit did not fix the issue I am having.

If I knew how to run this type of project, I would love to submit a PR but never worked with VSTS extensions.

@BlueBasher
Copy link
Owner

In your screenshot it shows that it compares the release with previous deployment Release-405.
Was that your last successful deployment? If so, maybe you need to check this box "Include workitems since previously completed deployment".

@jwar-gilson
Copy link
Author

@BlueBasher I checked that box and ran a new release with two work items. None of them updated.

2020-07-09T15:45:13.4239881Z ##[debug]Get WorkItemTrackingApi
2020-07-09T15:45:13.8298863Z ##[debug]Get workItemsRefs
2020-07-09T15:45:13.8307600Z Using Release as WorkItem Source
2020-07-09T15:45:14.2693327Z ##[debug]Using Release 704 as BaseRelease for 712
2020-07-09T15:45:14.4568377Z No workitems found to update.
2020-07-09T15:45:14.4569590Z ##[debug]task result: Succeeded
2020-07-09T15:45:14.4574970Z ##[debug]Processed: ##vso[task.complete result=Succeeded;]
2020-07-09T15:45:14.4691885Z ##[section]Finishing: WorkItem Updater

@Quent1L
Copy link

Quent1L commented Nov 24, 2023

Hi @BlueBasher, I have the same bug as the last two messages. Do you know if this bug has been fixed?

@BlueBasher
Copy link
Owner

As far as I know there should not be any bug that causes workitems not to be updated.
If something is not updated, it could be because of how the task is configured.
If the task is running in a Release Pipeline, often the checkbox "Include workitems since previously completed releases" needs to be checked (if that's what you want). DevOps itself shows workitems in the Release view based on the curernt release in comparison with the last successful Release for that specific Release Stage.

@Quent1L
Copy link

Quent1L commented Nov 24, 2023

Thanks @BlueBasher for your quick reply!

I'm trying to use your extension with Azure yaml pipelines like this :

   task: WorkItemUpdater@3
    displayName: "WorkItem Updater"
    inputs:
      workitemsSource: Build
      workItemType: Task
      updateAssignedTo: Never
      linkBuild: true
      comment: "TEST"
    continueOnError: true

When I launch my pipeline, the work item is recognised by azure but not by WorkItemUpdater :
image

##[debug]Get WorkItemTrackingApi
##[debug]Get workItemsRefs
Using Build as WorkItem Source
No workitems found to update.
##[debug]task result: Succeeded

Do you know why it doesn't work? Have I forgotten something?

@bhav-rach
Copy link

bhav-rach commented Aug 13, 2024

@BlueBasher I am getting the same issue now. It was working earlier. I get the "No workitems found to update." in the logs. I applied Filter as well.

@NikolayBieliashov
Copy link

NikolayBieliashov commented Sep 17, 2024

I have this situation. Have two separate task form deploy 1 and 2 artifacts, each has it's own Workitem Updater Task. I need to tag all work items in release.
image
Only tasks from the first artifacts were tagged, however, everything was linked properly.
I deploy not all artifacts every time though.

@PaulARoy
Copy link

PaulARoy commented Sep 24, 2024

Hi,
I encounter the same issue and I found why.

TLDR:getReleaseWorkItems only fetches the items of the main artifact

Source is here
getReleaseWorkItemsRefs(project: string, releaseId: number, baseReleaseId?: number, top?: number, artifactAlias?: string): Promise<ReleaseInterfaces.ReleaseWorkItemRef[]>;
https://github.com/microsoft/azure-devops-node-api/blob/efcb995db93fc08d6e0e731ce9ca76e9747723a7/api/ReleaseApi.ts#L109

By using it here without specifying the artifact

const releaseWorkItemRefs = await releaseClient.getReleaseWorkItemsRefs(settings.projectId, settings.releaseId, baseReleaseId);

We are only fetching the items related to the main one. It really isn't well documented and I had to explore myself the REST api to draw that conclusion.

The fix would be to loop on each artifact-alias of the release, maybe with
getAgentArtifactDefinitions(project: string, releaseId: number): Promise<ReleaseInterfaces.AgentArtifactDefinition[]>;
https://github.com/microsoft/azure-devops-node-api/blob/efcb995db93fc08d6e0e731ce9ca76e9747723a7/api/ReleaseApi.ts#L22

I did it with a hardcoded artifact-list on a powershell script at the moment.

@NikolayBieliashov
Copy link

NikolayBieliashov commented Sep 24, 2024 via email

@solonkooi
Copy link

Good afternoon
Will a fix be prepared for this issue?

@NikolayBieliashov
Copy link

NikolayBieliashov commented Feb 3, 2025 via email

@PaulARoy
Copy link

PaulARoy commented Feb 10, 2025

Hello,
Not sure ADO will fix it, I don't think it's a bug per se — without specifying the artifact it simply takes the main one.

We could technically list the artifacts and fetch the work items for each artifact on our end though. I ended up using powershell to do more specific work item rules and I didn't took the time to make a PR but do not hesitate if you want to @solonkooi

@solonkooi
Copy link

@PaulARoy Thanks for sharing your approach! Listing artifacts and fetching work items for each one sounds like a reasonable solution. Would you mind sharing a rough implementation of how you achieved it with PowerShell? It could be helpful for us to understand the approach better.

@PaulARoy
Copy link

PaulARoy commented Feb 26, 2025

Sure, here it is with custom rules (I removed some checks to make it easier to read) :

$AzureDevOpsPAT = $env:AZUREPAT
$OrganizationName = "[redacted]"
$Project = "[redacted]"

$AzureDevOpsAuthenticationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$UriOrgaProject = "https://$($OrganizationName).vsrm.visualstudio.com/$($Project)" 

$definitionId = $env:RELEASE_DEFINITIONID
$definitionEnvironmentId = $env:RELEASE_DEFINITIONENVIRONMENTID
$releaseId = $env:RELEASE_RELEASEID

$workItemTypes = @("Bug", "Technical Bug", "Product Backlog Item", "Technical Story")

$uriDeployments = $UriOrgaProject + "/_apis/release/deployments?definitionId=$($definitionId)&definitionEnvironmentId=$($definitionEnvironmentId)&deploymentStatus=Succeeded&api-version=7.1"
$deployments = Invoke-RestMethod -Uri $uriDeployments -Method get -Headers $AzureDevOpsAuthenticationHeader 

$baseReleaseId = $deployments.value[0].release.id # last succeeded deployment

$releaseUri = $UriOrgaProject + "/_apis/release/releases/$($releaseId)?api-version=7.1"
$release = Invoke-RestMethod -Uri $releaseUri -Method get -Headers $AzureDevOpsAuthenticationHeader 

Write-Host "Deploying from release: $($baseReleaseId) to release: $($releaseId)"
Foreach ($artifact in $release.artifacts)
{
  try {
    $uriWorkItems = $UriOrgaProject + "/_apis/release/releases/$($releaseId)/workitems?baseReleaseId=$($baseReleaseId)&artifactAlias=$($artifact.alias)&api-version=6.0-preview"
    $workItems = Invoke-RestMethod -Uri $uriWorkItems -Method get -Headers $AzureDevOpsAuthenticationHeader 

    Foreach ($workItem in $workItems.value) {
      $details = Invoke-RestMethod -Uri "https://dev.azure.com/$($OrganizationName)/$($Project)/_apis/wit/workitems/$($workItem.id)?fields=System.WorkItemType,System.Title,System.State&api-version=7.1" -Method get -Headers $AzureDevOpsAuthenticationHeader
      Add-Member -InputObject $details -NotePropertyName "artifact" -NotePropertyValue $artifact.alias

      If ($workItemTypes.Contains($details.fields.'System.WorkItemType')){            
        Write-Host "$($details.artifact): updating $($details.fields.'System.WorkItemType') $($details.id): ""$($details.fields.'System.Title')"" to State « To Validate »"
        $uriUpdateWorkItem = "https://dev.azure.com/$($OrganizationName)/$($Project)/_apis/wit/workitems/$($details.id)?api-version=7.1"
        
        If ($details.fields.'System.State' -eq "Done") {
          Write-Host "    [WARNING] Bypassing Done item"
        }
        Else {
          $assignedTo = "[redacted]"
          $Body = @(
            @{
              op    = 'replace'
              path  = '/fields/System.State'
              value = 'To Validate'
            },
            @{
              op    = 'add'
              path  = '/fields/System.AssignedTo'
              value = $assignedTo
            }
          ) | ConvertTo-Json -Depth 100 -Compress
          $response = Invoke-RestMethod -Uri $uriUpdateWorkItem -Method patch -Headers $AzureDevOpsAuthenticationHeader -Body $Body -ContentType "application/json-patch+json; charset=utf-8"
        }
      }
    }
  }
  catch { 
    Write-Host "An error occurred:"
    Write-Host $_
  }
}

I should warn you that we are dependant on whether the base deployment info still exists because they are removed after x days (default is 30).
That breaks the differential, but it also breaks it when you look at the work items in their Release interface.

@solonkooi
Copy link

@PaulARoy Thank you very much, this will help us a lot

@PaulARoy
Copy link

PaulARoy commented Feb 28, 2025

You're welcome!

I must admit these APIs aren't perfectly documented, I had to find code from other github projects calling the ADO APIs to unlock these hidden mysteries. The difficult part was getting the items from release to release. I wonder if I didn't even decompile the .net client to find that call.

Feel free to ask for any explanation or support!

Reference of the API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants