Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the optional 'source' property to the error/warning functions #1009

Merged
merged 7 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions node/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import crypto = require('crypto');
export var _knownVariableMap: { [key: string]: _KnownVariableInfo; } = {};

export var _vault: vm.Vault;
//-----------------------------------------------------
// Enums
//-----------------------------------------------------
export enum IssueSource {
CustomerScript = 'CustomerScript',
TaskInternal = 'TaskInternal'
}

//-----------------------------------------------------
// Validation Checks
Expand Down Expand Up @@ -282,12 +289,12 @@ export function _command(command: string, properties: any, message: string) {
_writeLine(taskCmd.toString());
}

export function _warning(message: string): void {
_command('task.issue', { 'type': 'warning' }, message);
export function _warning(message: string, source?: IssueSource): void {
_command('task.issue', { 'type': 'warning', 'source': source }, message);
}

export function _error(message: string): void {
_command('task.issue', { 'type': 'error' }, message);
export function _error(message: string, source?: IssueSource): void {
_command('task.issue', { 'type': 'error', 'source': source }, message);
}

export function _debug(message: string): void {
Expand Down
2 changes: 1 addition & 1 deletion node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-pipelines-task-lib",
"version": "4.7.0",
"version": "4.8.0",
"description": "Azure Pipelines Task SDK",
"main": "./task.js",
"typings": "./task.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions node/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export enum FieldType {
Url
}

export const IssueSource = im.IssueSource;

/** Platforms supported by our build agent */
export enum Platform {
Windows,
Expand Down
17 changes: 14 additions & 3 deletions powershell/VstsTaskSdk/LoggingCommandFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ $script:loggingCommandEscapeMappings = @( # TODO: WHAT ABOUT "="? WHAT ABOUT "%"
# TODO: BUG: Escape % ???
# TODO: Add test to verify don't need to escape "=".

$IssueSources = @{
CustomerScript = "CustomerScript"
TaskInternal = "TaskInternal"
}

<#
.SYNOPSIS
See https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md
Expand Down Expand Up @@ -286,7 +291,8 @@ function Write-TaskError {
[string]$SourcePath,
[string]$LineNumber,
[string]$ColumnNumber,
[switch]$AsOutput)
[switch]$AsOutput,
[string]$IssueSource)

Write-LogIssue -Type error @PSBoundParameters
}
Expand Down Expand Up @@ -322,7 +328,8 @@ function Write-TaskWarning {
[string]$SourcePath,
[string]$LineNumber,
[string]$ColumnNumber,
[switch]$AsOutput)
[switch]$AsOutput,
[string]$IssueSource)

Write-LogIssue -Type warning @PSBoundParameters
}
Expand Down Expand Up @@ -544,14 +551,18 @@ function Write-LogIssue {
[string]$SourcePath,
[string]$LineNumber,
[string]$ColumnNumber,
[switch]$AsOutput)
[switch]$AsOutput,
[AllowNull()]
[ValidateSet('CustomerScript', 'TaskInternal')]
[string]$IssueSource)

$command = Format-LoggingCommand -Area 'task' -Event 'logissue' -Data $Message -Properties @{
'type' = $Type
'code' = $ErrCode
'sourcepath' = $SourcePath
'linenumber' = $LineNumber
'columnnumber' = $ColumnNumber
'source' = $IssueSource
}
if ($AsOutput) {
return $command
Expand Down
2 changes: 1 addition & 1 deletion powershell/VstsTaskSdk/VstsTaskSdk.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
PowerShellVersion = '3.0'
FunctionsToExport = '*'
CmdletsToExport = ''
VariablesToExport = ''
VariablesToExport = 'IssueSources'
AliasesToExport = ''
PrivateData = @{
PSData = @{
Expand Down
4 changes: 4 additions & 0 deletions powershell/VstsTaskSdk/VstsTaskSdk.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ Export-ModuleMember -Function @(
'Get-ClientCertificate'
)

Export-ModuleMember -Variable @(
'IssueSources'
)

# Override Out-Default globally.
$null = New-Item -Force -Path "function:\global:Out-Default" -Value (Get-Command -CommandType Function -Name Out-Default -ListImported)
New-Alias -Name Out-Default -Value "global:Out-Default" -Scope global
Expand Down
3 changes: 2 additions & 1 deletion powershell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion powershell/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.17.0",
"version": "0.18.0",
"private": true,
"scripts": {
"build": "node make.js build",
Expand Down