Skip to content

Emit ##vso[task.logissue] from output device on Azure DevOps#8777

Open
Evangelink wants to merge 7 commits into
microsoft:mainfrom
Evangelink:dev/amauryleve/azdo-output-issues
Open

Emit ##vso[task.logissue] from output device on Azure DevOps#8777
Evangelink wants to merge 7 commits into
microsoft:mainfrom
Evangelink:dev/amauryleve/azdo-output-issues

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Fixes #5979.

When running on Azure DevOps (TF_BUILD=true) TerminalOutputDevice now automatically prefixes ErrorMessageOutputDeviceData, ExceptionOutputDeviceData and WarningMessageOutputDeviceData with a ##vso[task.logissue type=error|warning] line. The message therefore shows up on the Azure Pipelines build summary instead of being just colored text in the agent log.

This is intentionally implemented in the platform (not in Microsoft.Testing.Extensions.AzureDevOpsReport) because the AzureDevOpsReport extension only consumes TestNodeUpdateMessage and cannot intercept arbitrary IOutputDevice calls. Any extension that emits error/warning output (e.g. HangDump, CrashDump, Retry, TrxReport, HtmlReport, ServerTestHost, ...) now benefits automatically.

Escaping

The escaping rules (;%3B, \r%0D, \n%0A) match the ones used by the existing AzureDevOpsReport extension so the multi-line stack traces produced by Exception.ToString() collapse into a single ##vso[...] command.

Mapping

Output device data Severity
ErrorMessageOutputDeviceData error
ExceptionOutputDeviceData error
WarningMessageOutputDeviceData warning

Opt-out

The behavior can be disabled per-run by setting:

TESTINGPLATFORM_AZDO_OUTPUT=off

(false and 0 are also recognized.)

Notes

  • Writes go through ITerminalTestReporter.WriteMessage (normal mode) or WriteToStandardErrorAsync (--list-tests --output json mode) so that the AzDO line integrates with the active progress UI redraw logic rather than racing the raw console.
  • The AzDO line is emitted before the existing colored output to keep the human-readable rendering intact.
  • A follow-up PR will tackle #5951 (item 4) (rich job summary + per-test timeline progress + configurable stack-frame filter).

Tests

  • New AzureDevOpsLogIssueFormatterTests covers detection (TF_BUILD, opt-out, case sensitivity), formatting, and escaping.
  • Full Microsoft.Testing.Platform.UnitTests run: 1019 passed, 2 skipped, 0 failed.
  • Full Microsoft.Testing.Extensions.UnitTests run: 362 passed, 4 skipped, 0 failed.

When running on Azure DevOps (TF_BUILD=true) the output device now
automatically prefixes ErrorMessageOutputDeviceData,
ExceptionOutputDeviceData and WarningMessageOutputDeviceData with a
`##vso[task.logissue type=error|warning]` line so that the message
surfaces on the Azure Pipelines build summary instead of being just
colored text in the agent log.

The escaping rules (`;` -> `%3B`, `\r` -> `%0D`, `\n` ->
`%0A`) match the ones used by the existing
`Microsoft.Testing.Extensions.AzureDevOpsReport` extension and the
behavior can be disabled per-run by setting
`TESTINGPLATFORM_AZDO_OUTPUT=off|false|0`.

Fixes microsoft#5979.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 2, 2026 22:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances Microsoft.Testing.Platform’s terminal output so that, when running on Azure DevOps agents (TF_BUILD=true), error/warning output emitted via TerminalOutputDevice also produces ##vso[task.logissue type=error|warning]... logging commands. This makes warnings/errors appear in the Azure Pipelines build summary (not just as colored log lines), and supports an opt-out via TESTINGPLATFORM_AZDO_OUTPUT=off|false|0.

Changes:

  • Added an AzureDevOpsLogIssueFormatter helper to detect AzDO environment and format/escape task.logissue commands.
  • Updated TerminalOutputDevice to emit task.logissue lines before existing colored output for error/warning/exception output device data when in AzDO.
  • Added unit tests covering environment detection, formatting, and escaping.
Show a summary per file
File Description
src/Platform/Microsoft.Testing.Platform/OutputDevice/AzureDevOpsLogIssueFormatter.cs New helper for AzDO detection and formatting/escaping ##vso[task.logissue] lines.
src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs Emits task.logissue commands for warnings/errors/exceptions when running under Azure DevOps.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/AzureDevOpsLogIssueFormatterTests.cs New tests validating AzDO detection and task.logissue formatting/escaping behavior.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Comment thread src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs Outdated
Evangelink and others added 2 commits June 3, 2026 09:59
Per the official Azure Pipelines logging-command spec, the message body must also escape '%' as '%25' (FIRST, so other replacements aren't double-encoded) and ']' as '%5D'. Updated Escape + added regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 12:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs Outdated
Comment thread src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs Outdated
Evangelink and others added 2 commits June 3, 2026 16:43
Pipeline logging commands need stdout to be picked up by the AzDO agent, but JSON list mode must keep stdout clean. Drop the AzDO command in that mode and rely on the existing stderr warning/error text for human visibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 15:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Evangelink and others added 2 commits June 3, 2026 22:51
Acceptance tests assert against literal stdout content. When tests run on Azure DevOps, TF_BUILD=true is inherited by child test hosts, causing the new TerminalOutputDevice to emit ##vso[task.logissue type=...] commands that break index-based line assertions (e.g. Help_WhenNoExtensionRegisteredAndUnknownOptionIsSpecified_OutputDefaultHelpContentAndUnknownOption).

- TestHost.ExecuteAsync now injects TESTINGPLATFORM_AZDO_OUTPUT=off by default (opt-out parameter).

- WellKnownEnvironmentVariables.ToSkipEnvironmentVariables now skips TESTINGPLATFORM_AZDO_OUTPUT so the parent value doesn't bleed in.

- TerminalOutputDeviceTests sanitizes its assertion message so a failure does not itself contain a literal ##vso command (Copilot review feedback).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The new bool parameter shifted the CancellationToken positional argument; callers now pass cancellationToken as a named argument.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 22:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 8/8 changed files
  • Comments generated: 0 new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should output device log issues with Azure syntax when running on Azure?

2 participants