PatrickNolan
PatrickNolan

Reputation: 1979

How to update custom field on completed Azure Devops workitem with Build number

I would like to add a step in my Azure Devops build pipeline to do the following

  1. Identify any workitems that are closed\completed and associated with changesets included in the current build
  2. Update custom field on workitems identified with current build number

Does anyone know if there is an existing marketplace step to do this? If not, has anyone written a script to do this in the past that they could share?

Upvotes: 0

Views: 1976

Answers (3)

PatrickNolan
PatrickNolan

Reputation: 1979

I ended up creating a new marketplace extension to solve this problem.

The extension allows you to update a field on the workitem with the associated build number.

Logic is as follows

  1. Developer checks in code with associated workitem
  2. Build pipeline triggers
  3. Final step of build process is ReleaseNotesHub Update Build Number step
  4. ReleaseNotesHub Step will get workitems for associated changesets
  5. ReleaseNotesHub Step will update field on workitems with build number

The ReleaseNotesHub step is very configurable and great for leveraging the AzureDevops\TFS query designer for querying workitems associated with a particular build.

The marketplace extension can be found here

enter image description here

Upvotes: 1

LoLance
LoLance

Reputation: 28196

Identify any workitems that are closed\completed and associated with changesets included in the current build

To get workitems associated with current build, you can use Builds - Get Build Work Items Refs:

GET https://{instance}/{collection}/{project}/_apis/build/builds/{buildId}/workitems?api-version=5.0

To get workitems that are closed/completed, you can use Wiql - Query By Wiql:

POST https://{instance}/{collection}/{project}/{team}/_apis/wit/wiql?api-version=5.0

To update field of a workitem, you can use Workitem-update:

PATCH https://{instance}/CollectionName/_apis/wit/workitems/{id}?api-version=5.0

You can use Powershell script to execute these apis, $(Build.BuildId) variable represents the buildID and $(Build.BuildNumber) variable represents the buildNumber, you can check predefined variables.

Upvotes: 1

Martyn C
Martyn C

Reputation: 1161

The WorkItem Updater addon in the Marketplace will help you achieve some of what you are asking.

You can look at a list of work items that are associated with your build or release, or the results of a query you have already saved in Azure DevOps.

You then have the option to modify a number of built-in fields or define the custom ones you want to update.

Here is a reference for the settings screen you will get in your pipeline.

enter image description here

Upvotes: -1

Related Questions