Skip to content

Commit

Permalink
Renamed the token to the correlation ID. (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisNikulin5 committed Mar 18, 2024
1 parent 4c60d46 commit b281dc9
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 67 deletions.
4 changes: 4 additions & 0 deletions node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 4.x

### 4.10.0

- Added `correlation ID` property for logging commands [#1021](https://github.com/microsoft/azure-pipelines-task-lib/pull/1021)

### 4.9.0

- Added internal feature helpers [#1010](https://github.com/microsoft/azure-pipelines-task-lib/pull/1010)
Expand Down
12 changes: 6 additions & 6 deletions node/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import crypto = require('crypto');
export var _knownVariableMap: { [key: string]: _KnownVariableInfo; } = {};

export var _vault: vm.Vault;
var _taskSdkToken: string;
var _commandCorrelationId: string;

//-----------------------------------------------------
// Enums
Expand Down Expand Up @@ -306,11 +306,11 @@ export function _command(command: string, properties: any, message: string) {
}

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

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

export function _debug(message: string): void {
Expand Down Expand Up @@ -756,9 +756,9 @@ export function _loadData(): void {
}
_debug('loaded ' + loaded);

let token = process.env["TASK_SDK_COMMAND_TOKEN"];
delete process.env["TASK_SDK_COMMAND_TOKEN"];
_taskSdkToken = token ? String(token) : "";
let correlationId = process.env["COMMAND_CORRELATION_ID"];
delete process.env["COMMAND_CORRELATION_ID"];
_commandCorrelationId = correlationId ? String(correlationId) : "";

// store public variable metadata
let names: string[];
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.10.0",
"version": "4.10.1",
"description": "Azure Pipelines Task SDK",
"main": "./task.js",
"typings": "./task.d.ts",
Expand Down
30 changes: 15 additions & 15 deletions node/test/taskissuecommandtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as tl from '../_build/task';
import { IssueSource, _loadData } from '../_build/internal';


describe('Task Issue command test without token', function () {
describe('Task Issue command test without correlation ID', function () {

before(function (done) {
try {
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('Task Issue command test without token', function () {
})
});

describe('Task Issue command test with token', function () {
describe('Task Issue command test with correlation ID', function () {

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

process.env['TASK_SDK_COMMAND_TOKEN'] = 'test_token123';
process.env['COMMAND_CORRELATION_ID'] = 'test_id123';
_loadData();
done();
});

after(function (done) {
delete process.env['TASK_SDK_COMMAND_TOKEN'];
delete process.env['COMMAND_CORRELATION_ID'];
_loadData();
done();
});

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

assert.equal(process.env['TASK_SDK_COMMAND_TOKEN'], undefined);
assert.equal(process.env['COMMAND_CORRELATION_ID'], undefined);

done();
})

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

process.env['AGENT_VERSION'] = '2.115.0'
let variable = tl.getVariable('TASK_SDK_COMMAND_TOKEN');
let taskVariable = tl.getTaskVariable('TASK_SDK_COMMAND_TOKEN');
let variable = tl.getVariable('COMMAND_CORRELATION_ID');
let taskVariable = tl.getTaskVariable('COMMAND_CORRELATION_ID');
assert.equal(variable, undefined);
assert.equal(taskVariable, undefined);

done();
})

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

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

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

var output = stdStream.getContents();

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

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

var output = stdStream.getContents();

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

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

var output = stdStream.getContents();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[CmdletBinding()]
param()

$env:COMMAND_CORRELATION_ID = "test_id123"

# Arrange.
. $PSScriptRoot\..\lib\Initialize-Test.ps1
Invoke-VstsTaskScript -ScriptBlock {
$vstsModule = Get-Module -Name VstsTaskSdk

# 1
Assert-AreEqual $null $env:COMMAND_CORRELATION_ID "SDK removes the correlation ID after loading."

# 2
$actual = & $vstsModule Get-TaskVariable -Name "COMMAND_CORRELATION_ID"
Assert-AreEqual $null $actual "The correlation ID is inaccessible using task variables."

# 3
$actual = & $vstsModule Write-TaskError -Message "test error" -AsOutput
$expected = "##vso[task.logissue correlationId=test_id123;source=TaskInternal;type=error]test error"
Assert-TaskIssueMessagesAreEqual $expected $actual "The default 'TastInternal' source and the correlation ID were added for errors."

# 4
$actual = & $vstsModule Write-TaskWarning -Message "test warning" -AsOutput
$expected = "##vso[task.logissue correlationId=test_id123;source=TaskInternal;type=warning]test warning"
Assert-TaskIssueMessagesAreEqual $expected $actual "The default 'TastInternal' source and the correlation ID were added for warnings."

# 5
$actual = & $vstsModule Write-TaskError -Message "test error" -IssueSource $IssueSources.CustomerScript -AsOutput
$expected = "##vso[task.logissue correlationId=test_id123;source=CustomerScript;type=error]test error"
Assert-TaskIssueMessagesAreEqual $expected $actual "Adds the specified issue source and the correlation ID for errors."

# 6
$actual = & $vstsModule Write-TaskWarning -Message "test warning" -IssueSource $IssueSources.CustomerScript -AsOutput
$expected = "##vso[task.logissue correlationId=test_id123;source=CustomerScript;type=warning]test warning"
Assert-TaskIssueMessagesAreEqual $expected $actual "Adds the specified issue source and the correlation ID for warnings."
}

This file was deleted.

8 changes: 4 additions & 4 deletions powershell/VstsTaskSdk/LoggingCommandFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ $script:loggingCommandEscapeMappings = @( # TODO: WHAT ABOUT "="? WHAT ABOUT "%"
# TODO: BUG: Escape % ???
# TODO: Add test to verify don't need to escape "=".

$taskSDKToken = $env:TASK_SDK_COMMAND_TOKEN
if ($null -ne $taskSDKToken)
$commandCorrelationId = $env:COMMAND_CORRELATION_ID
if ($null -ne $commandCorrelationId)
{
[System.Environment]::SetEnvironmentVariable("TASK_SDK_COMMAND_TOKEN", $null)
[System.Environment]::SetEnvironmentVariable("COMMAND_CORRELATION_ID", $null)
}

$IssueSources = @{
Expand Down Expand Up @@ -569,7 +569,7 @@ function Write-LogIssue {
'linenumber' = $LineNumber
'columnnumber' = $ColumnNumber
'source' = $IssueSource
'token' = $taskSDKToken
'correlationId' = $commandCorrelationId
}
if ($AsOutput) {
return $command
Expand Down
3 changes: 1 addition & 2 deletions 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.20.0",
"version": "0.20.1",
"private": true,
"scripts": {
"build": "node make.js build",
Expand Down

0 comments on commit b281dc9

Please sign in to comment.