Skip to content

Commit ab88524

Browse files
Renamed the token to the correlation ID. (#1027)
1 parent 6a56192 commit ab88524

10 files changed

+70
-67
lines changed

node/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 4.x
44

5+
### 4.10.0
6+
7+
- Added `correlation ID` property for logging commands [#1021](https://github.com/microsoft/azure-pipelines-task-lib/pull/1021)
8+
59
### 4.9.0
610

711
- Added internal feature helpers [#1010](https://github.com/microsoft/azure-pipelines-task-lib/pull/1010)

node/internal.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import crypto = require('crypto');
2020
export var _knownVariableMap: { [key: string]: _KnownVariableInfo; } = {};
2121

2222
export var _vault: vm.Vault;
23-
var _taskSdkToken: string;
23+
var _commandCorrelationId: string;
2424

2525
//-----------------------------------------------------
2626
// Enums
@@ -306,11 +306,11 @@ export function _command(command: string, properties: any, message: string) {
306306
}
307307

308308
export function _warning(message: string, source: IssueSource = IssueSource.TaskInternal): void {
309-
_command('task.issue', { 'type': 'warning', 'source': source, 'token': _taskSdkToken }, message);
309+
_command('task.issue', { 'type': 'warning', 'source': source, 'correlationId': _commandCorrelationId }, message);
310310
}
311311

312312
export function _error(message: string, source: IssueSource = IssueSource.TaskInternal): void {
313-
_command('task.issue', { 'type': 'error', 'source': source, 'token': _taskSdkToken }, message);
313+
_command('task.issue', { 'type': 'error', 'source': source, 'correlationId': _commandCorrelationId }, message);
314314
}
315315

316316
export function _debug(message: string): void {
@@ -756,9 +756,9 @@ export function _loadData(): void {
756756
}
757757
_debug('loaded ' + loaded);
758758

759-
let token = process.env["TASK_SDK_COMMAND_TOKEN"];
760-
delete process.env["TASK_SDK_COMMAND_TOKEN"];
761-
_taskSdkToken = token ? String(token) : "";
759+
let correlationId = process.env["COMMAND_CORRELATION_ID"];
760+
delete process.env["COMMAND_CORRELATION_ID"];
761+
_commandCorrelationId = correlationId ? String(correlationId) : "";
762762

763763
// store public variable metadata
764764
let names: string[];

node/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-pipelines-task-lib",
3-
"version": "4.10.0",
3+
"version": "4.10.1",
44
"description": "Azure Pipelines Task SDK",
55
"main": "./task.js",
66
"typings": "./task.d.ts",

node/test/taskissuecommandtests.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as tl from '../_build/task';
77
import { IssueSource, _loadData } from '../_build/internal';
88

99

10-
describe('Task Issue command test without token', function () {
10+
describe('Task Issue command test without correlation ID', function () {
1111

1212
before(function (done) {
1313
try {
@@ -81,7 +81,7 @@ describe('Task Issue command test without token', function () {
8181
})
8282
});
8383

84-
describe('Task Issue command test with token', function () {
84+
describe('Task Issue command test with correlation ID', function () {
8585

8686
before(function (done) {
8787
try {
@@ -90,38 +90,38 @@ describe('Task Issue command test with token', function () {
9090
assert.fail('Failed to load task lib: ' + err.message);
9191
}
9292

93-
process.env['TASK_SDK_COMMAND_TOKEN'] = 'test_token123';
93+
process.env['COMMAND_CORRELATION_ID'] = 'test_id123';
9494
_loadData();
9595
done();
9696
});
9797

9898
after(function (done) {
99-
delete process.env['TASK_SDK_COMMAND_TOKEN'];
99+
delete process.env['COMMAND_CORRELATION_ID'];
100100
_loadData();
101101
done();
102102
});
103103

104-
it('removes the token from env var', function (done) {
104+
it('removes the correlation ID from env var', function (done) {
105105
this.timeout(1000);
106106

107-
assert.equal(process.env['TASK_SDK_COMMAND_TOKEN'], undefined);
107+
assert.equal(process.env['COMMAND_CORRELATION_ID'], undefined);
108108

109109
done();
110110
})
111111

112-
it('doesn\'t provide the token using task variables', function (done) {
112+
it('doesn\'t provide the correlation ID using task variables', function (done) {
113113
this.timeout(1000);
114114

115115
process.env['AGENT_VERSION'] = '2.115.0'
116-
let variable = tl.getVariable('TASK_SDK_COMMAND_TOKEN');
117-
let taskVariable = tl.getTaskVariable('TASK_SDK_COMMAND_TOKEN');
116+
let variable = tl.getVariable('COMMAND_CORRELATION_ID');
117+
let taskVariable = tl.getTaskVariable('COMMAND_CORRELATION_ID');
118118
assert.equal(variable, undefined);
119119
assert.equal(taskVariable, undefined);
120120

121121
done();
122122
})
123123

124-
it('adds the token for task.issue messages', function (done) {
124+
it('adds the correlation ID for task.issue messages', function (done) {
125125
this.timeout(1000);
126126

127127
var stdStream = testutil.createStringStream();
@@ -130,8 +130,8 @@ describe('Task Issue command test with token', function () {
130130
tl.warning("Test warning", IssueSource.TaskInternal)
131131

132132
var expected = testutil.buildOutput(
133-
['##vso[task.issue type=error;source=CustomerScript;token=test_token123;]Test error',
134-
'##vso[task.issue type=warning;source=TaskInternal;token=test_token123;]Test warning']);
133+
['##vso[task.issue type=error;source=CustomerScript;correlationId=test_id123;]Test error',
134+
'##vso[task.issue type=warning;source=TaskInternal;correlationId=test_id123;]Test warning']);
135135

136136
var output = stdStream.getContents();
137137

@@ -149,8 +149,8 @@ describe('Task Issue command test with token', function () {
149149
tl.warning("Test warning");
150150

151151
var expected = testutil.buildOutput(
152-
['##vso[task.issue type=error;source=TaskInternal;token=test_token123;]Test error',
153-
'##vso[task.issue type=warning;source=TaskInternal;token=test_token123;]Test warning']);
152+
['##vso[task.issue type=error;source=TaskInternal;correlationId=test_id123;]Test error',
153+
'##vso[task.issue type=warning;source=TaskInternal;correlationId=test_id123;]Test warning']);
154154

155155
var output = stdStream.getContents();
156156

@@ -168,7 +168,7 @@ describe('Task Issue command test with token', function () {
168168

169169
var expected = testutil.buildOutput(
170170
['##vso[task.debug]task result: Failed',
171-
'##vso[task.issue type=error;source=TaskInternal;token=test_token123;]failed msg',
171+
'##vso[task.issue type=error;source=TaskInternal;correlationId=test_id123;]failed msg',
172172
'##vso[task.complete result=Failed;]failed msg']);
173173

174174
var output = stdStream.getContents();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[CmdletBinding()]
2+
param()
3+
4+
$env:COMMAND_CORRELATION_ID = "test_id123"
5+
6+
# Arrange.
7+
. $PSScriptRoot\..\lib\Initialize-Test.ps1
8+
Invoke-VstsTaskScript -ScriptBlock {
9+
$vstsModule = Get-Module -Name VstsTaskSdk
10+
11+
# 1
12+
Assert-AreEqual $null $env:COMMAND_CORRELATION_ID "SDK removes the correlation ID after loading."
13+
14+
# 2
15+
$actual = & $vstsModule Get-TaskVariable -Name "COMMAND_CORRELATION_ID"
16+
Assert-AreEqual $null $actual "The correlation ID is inaccessible using task variables."
17+
18+
# 3
19+
$actual = & $vstsModule Write-TaskError -Message "test error" -AsOutput
20+
$expected = "##vso[task.logissue correlationId=test_id123;source=TaskInternal;type=error]test error"
21+
Assert-TaskIssueMessagesAreEqual $expected $actual "The default 'TastInternal' source and the correlation ID were added for errors."
22+
23+
# 4
24+
$actual = & $vstsModule Write-TaskWarning -Message "test warning" -AsOutput
25+
$expected = "##vso[task.logissue correlationId=test_id123;source=TaskInternal;type=warning]test warning"
26+
Assert-TaskIssueMessagesAreEqual $expected $actual "The default 'TastInternal' source and the correlation ID were added for warnings."
27+
28+
# 5
29+
$actual = & $vstsModule Write-TaskError -Message "test error" -IssueSource $IssueSources.CustomerScript -AsOutput
30+
$expected = "##vso[task.logissue correlationId=test_id123;source=CustomerScript;type=error]test error"
31+
Assert-TaskIssueMessagesAreEqual $expected $actual "Adds the specified issue source and the correlation ID for errors."
32+
33+
# 6
34+
$actual = & $vstsModule Write-TaskWarning -Message "test warning" -IssueSource $IssueSources.CustomerScript -AsOutput
35+
$expected = "##vso[task.logissue correlationId=test_id123;source=CustomerScript;type=warning]test warning"
36+
Assert-TaskIssueMessagesAreEqual $expected $actual "Adds the specified issue source and the correlation ID for warnings."
37+
}

powershell/Tests/L0/Write-LoggingCommand.WritesTaskIssueWithToken.ps1

-37
This file was deleted.

powershell/VstsTaskSdk/LoggingCommandFunctions.ps1

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ $script:loggingCommandEscapeMappings = @( # TODO: WHAT ABOUT "="? WHAT ABOUT "%"
88
# TODO: BUG: Escape % ???
99
# TODO: Add test to verify don't need to escape "=".
1010

11-
$taskSDKToken = $env:TASK_SDK_COMMAND_TOKEN
12-
if ($null -ne $taskSDKToken)
11+
$commandCorrelationId = $env:COMMAND_CORRELATION_ID
12+
if ($null -ne $commandCorrelationId)
1313
{
14-
[System.Environment]::SetEnvironmentVariable("TASK_SDK_COMMAND_TOKEN", $null)
14+
[System.Environment]::SetEnvironmentVariable("COMMAND_CORRELATION_ID", $null)
1515
}
1616

1717
$IssueSources = @{
@@ -569,7 +569,7 @@ function Write-LogIssue {
569569
'linenumber' = $LineNumber
570570
'columnnumber' = $ColumnNumber
571571
'source' = $IssueSource
572-
'token' = $taskSDKToken
572+
'correlationId' = $commandCorrelationId
573573
}
574574
if ($AsOutput) {
575575
return $command

powershell/package-lock.json

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

powershell/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.20.0",
2+
"version": "0.20.1",
33
"private": true,
44
"scripts": {
55
"build": "node make.js build",

0 commit comments

Comments
 (0)