9
votes

I am using SendGrid email extension to trigger a custom email notification after the CI/CD process is complete in VSTS. This email task has HTML content in it which includes some content fetched using standard build/release variables (https://docs.microsoft.com/en-us/vsts/build-release/concepts/definitions/build/variables?tabs=batch).

How do I include associated code changes, check-in comments and linked work items for a particular release in the custom email? Are there any variables I can use? Any work around?

2

2 Answers

8
votes

There aren’t the built-in variables that can get code changes, check-in comments and linked work items.

You can get them through REST API during build or release:

  1. Get build changes and work items through Get Build Changes REST API (Build id variable: Build.BuildId during build or Release.Artifacts.{Artifact alias}.BuildId during release) Note: using Build.SourceVersion to get latest version)
  2. Git: Get commit message through Get a batch of commits by a list of commit IDs REST API
  3. TFVC: Get check-in comment through Get list of changesets by a list of IDS REST API
  4. To get changed items, you can use get commit with changed items or Get list of changes in a changeset REST API.

No API to get detail code changes, but you may refer to this related issue: Lines of Code modified in each Commit in TFS rest api. How do i get?

0
votes

Assuming TFS (which isn't specified in the question or tags), you could also call tf.exe directly to get some of that info. If you don't care about the output format, then the output of the following command produces a report of the Changeset details.

tf vc changeset <changeset id> /loginType:OAuth /login:.,<token> /noprompt

Where <changeset id> is the numeric Build.SourceVersion, and <token> is the System.AccessToken.

Comments and source code edits listing are included in the report.

Note: the agent job has to be given the "Allow scripts to access the OAuth token" permission (check box on the Agent Job properties).

See the updated link below for details on how to access the build variables. Same content as in the question, but new link. Both currently work.

https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml