Work items, pull requests and pipeline runs
Azure DevOps keeps three kinds of work in every project: work items on Boards, pull requests in Repos, and runs in Pipelines. This guide covers how to find and change each one, and the details that trip a first attempt.
Finding work items
azuredevops_query_work_items takes a WIQL query, Azure DevOps' SQL-like query language. Start from one of these and change the conditions:
-- What's assigned to me and still open
SELECT [System.Id] FROM WorkItems
WHERE [System.TeamProject] = @project
AND [System.AssignedTo] = @me
AND [System.State] NOT IN ('Closed', 'Done', 'Removed')
ORDER BY [System.ChangedDate] DESC
-- Bugs in the team's current sprint
SELECT [System.Id] FROM WorkItems
WHERE [System.WorkItemType] = 'Bug'
AND [System.IterationPath] = @currentIteration('[Web]\Web Team')
-- Anything changed in the last week
SELECT [System.Id] FROM WorkItems
WHERE [System.TeamProject] = @project AND [System.ChangedDate] >= @today - 7@project needs the tool's project argument, or a project pinned to the scene. @me is the connected person. @currentIteration needs the team spelled out as '[Project]\Team', because the query doesn't run in a team's context.
The query decides which work items match. Which fields come back is set separately: every row has id, type, title, state, assignee, iteration and a link, and fields adds more by reference name, such as Microsoft.VSTS.Common.Priority or System.Tags. azuredevops_get_work_item returns every field of one item, with its parent, children and linked commits and pull requests, and its latest comments.
Changing work items
States depend on the project's process, so check one item of the same type before moving another. Agile uses New, Active, Resolved and Closed. Scrum uses New, Approved, Committed and Done. Basic uses To Do, Doing and Done. A state that the type doesn't have fails with a rule error naming the field.
A new work item always opens in its type's first state. To create one in a later state, pass state with the create: the item is created, then moved, in the one call. If the move is refused the item still exists, and the result says why in stateNotSet. Move it with an update; creating it again would make a second one.
The common fields have their own arguments: title, state, assignee (an email works), area, iteration and tags. Anything else goes in fields by reference name, for example {"Microsoft.VSTS.Scheduling.StoryPoints": 3}. Descriptions and comments are HTML, so a line break is <br> and a list is <ul>.
parent_id makes a new or existing item a child of another, the way tasks sit under a user story.
Reviewing pull requests
azuredevops_list_pull_requests with mine: "reviewing" is the review queue: pull requests where you're a reviewer. Each reviewer's vote reads as approved, approved with suggestions, waiting for author, rejected or no vote.
azuredevops_get_pull_request returns the description, the files the change touches and the discussion so far, with file and line for inline comments. Read the changed files with azuredevops_read_file on the source branch.
A comment on one line takes file_path and line, counted on the new version of the file. Pull request comments are Markdown, unlike work item comments.
Finding out why a pipeline failed
azuredevops_list_runs with result: "failed" finds the broken runs. A run's id is its build id, so it goes straight into azuredevops_get_run.
azuredevops_get_run returns the stages, and for each failed step the errors it reported and the last 60 lines of its log. That is usually enough to say what broke, since a failing test or command reports itself in the last lines of its step.
azuredevops_run_pipeline queues a new run, on another branch if you pass one. A variable can only be set if the pipeline lets users override it when running; template parameters are whatever the pipeline's YAML declares.