Skip to content

Instantly share code, notes, and snippets.

@CurlyBytes
Forked from GerryWilko/workitem-poster.yml
Created May 4, 2022 08:21
Show Gist options
  • Select an option

  • Save CurlyBytes/ca031f31db3418623d76d5b4f83c9b75 to your computer and use it in GitHub Desktop.

Select an option

Save CurlyBytes/ca031f31db3418623d76d5b4f83c9b75 to your computer and use it in GitHub Desktop.
Azure Pipelines Task to Post Comment to Linked Work Items (Bash)
- bash: | # Access Token should need Build Read, Work Item Read & Write, Member Entitlement Management Read
curl -u test@test.com:access-token-xxxxxxxxxxx https://dev.azure.com/{organisation}/{project}/_apis/build/builds/$(build.buildId)/workitems?api-version=6.0 | jq '.value[] | .id' |
while IFS=$"\n" read -r c; do
wid=$(echo $c | tr -dc '0-9')
echo
echo Posting status to work item: $wid
echo
curl -u test@test.com:access-token-xxxxxxxxxxx https://dev.azure.com/{organisation}/{project}/_apis/wit/workItems/$wid/comments?api-version=6.0-preview.3 -X POST --data '{"text": "Build $(Build.BuildNumber) completed with status: $(Agent.JobStatus)"}' -H 'Content-Type: application/json'
echo
done
displayName: 'Post status to work items'
condition: always()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment