Christian Kittel
Christian Kittel

Reputation: 1

Build step after gated checkin successful

at the moment we are migrating our XAML-Builds to new TFS Build-System. We have our TFS on premise.

Problem is about gated checkin: After the gated checkin is successful, we create a code review workitem. This is not a problem in XAML Builds. We had written an activity. This activity is executed after the real check-in.

The question is: Is there a way to create a build step (in the new Build-System (vnext)) after the gated checkin is successful? We need the Changeset-Id the build created.

Upvotes: 0

Views: 86

Answers (1)

starian chen-MSFT
starian chen-MSFT

Reputation: 33708

First, you could associate work item when you check in changes, then the changeset will be associated to corresponding work item after verifying build.

Secondly, you can associate changeset to a work item by using update work item REST API:

For example:

PATCH https://[account].visualstudio.com/DefaultCollection/_apis/wit/workitems/[work item id]?api-version=1.0

ContentType: application/json-patch+json

Body:

[
  {
    "op": "add",
    "path": "/relations/-",
    "value": {
      "rel": "ArtifactLink",
      "url": "vstfs:///VersionControl/Changeset/[changeset ID]",
      "attributes": {
        "comment": "apitest",
         "name": "Fixed in Changeset"
      }
    }
  }
]

You can use Build.SourceVersion to get ChangeSet. Build variables

Simple sample to get chageset through PowerShell task:

Arguments: -v $(Build.SourceVersion)

Scripts:

param(
[string]$v
)
Write-Host $v

A blog about calling REST API during build: Calling VSTS APIs with PowerShell

Upvotes: 0

Related Questions