Skip to content

Commit

Permalink
Merge branch 'master' into users/ansheno/aaAgentless
Browse files Browse the repository at this point in the history
  • Loading branch information
Anumita authored Dec 17, 2019
2 parents a642f21 + 4a50577 commit 9c55811
Show file tree
Hide file tree
Showing 40 changed files with 513 additions and 129 deletions.
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ Tasks/PublishPipelineMetadataV0/* @vithati @nidabas

Tasks/PublishSymbolsV2/* @arunkm @mihaif @jahsu-MSFT @fadnavistanmay @owenhuynMSFT

Tasks/PublishTestResultsV1/* @shaiku
Tasks/PublishTestResultsV1/* @shailesh-sk

Tasks/PublishTestResultsV2/* @shaiku
Tasks/PublishTestResultsV2/* @shailesh-sk

Tasks/ContainerStructureTestV0/* @shaiku @navin22
Tasks/ContainerStructureTestV0/* @shailesh-sk @navin22

Tasks/PublishToAzureServiceBusV1/* @vithati

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"loc.messages.UpdatedAppServiceConfigurationSettings": "Updated App Service Configuration settings.",
"loc.messages.UpdatedAppServiceApplicationSettings": "Updated App Service Application settings and Kudu Application settings.",
"loc.messages.UpdatingAppServiceConnectionStrings": "Updating App Service Connection Strings. Data: %s",
"loc.messages.UpdatedAppServiceConnectionStrings": "Updated App Service Connection Strings. Data: %s",
"loc.messages.UpdatedAppServiceConnectionStrings": "Updated App Service Connection Strings.",
"loc.messages.FailedToUpdateAppServiceApplicationSettings": "Failed to update App service '%s' application settings. Error: %s",
"loc.messages.FailedToUpdateAppServiceConfigSlotSettings": "Failed to update App service '%s' Configuration Slot Settings. Error: %s",
"loc.messages.FailedToUpdateAppServiceConnectionStrings": "Failed to update App service '%s' Connection Strings. Error: %s",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureAppServiceSettingsV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 160,
"Patch": 1
"Patch": 2
},
"preview": "true",
"minimumAgentVersion": "2.104.1",
Expand Down Expand Up @@ -157,7 +157,7 @@
"UpdatedAppServiceConfigurationSettings": "Updated App Service Configuration settings.",
"UpdatedAppServiceApplicationSettings": "Updated App Service Application settings and Kudu Application settings.",
"UpdatingAppServiceConnectionStrings" : "Updating App Service Connection Strings. Data: %s",
"UpdatedAppServiceConnectionStrings" : "Updated App Service Connection Strings. Data: %s",
"UpdatedAppServiceConnectionStrings" : "Updated App Service Connection Strings.",
"FailedToUpdateAppServiceApplicationSettings": "Failed to update App service '%s' application settings. Error: %s",
"FailedToUpdateAppServiceConfigSlotSettings" : "Failed to update App service '%s' Configuration Slot Settings. Error: %s",
"FailedToUpdateAppServiceConnectionStrings": "Failed to update App service '%s' Connection Strings. Error: %s",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureAppServiceSettingsV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 160,
"Patch": 1
"Patch": 2
},
"preview": "true",
"minimumAgentVersion": "2.104.1",
Expand Down
43 changes: 41 additions & 2 deletions Tasks/BashV3/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Bash Suite', function () {
it('Runs an inline script correctly', (done: MochaDone) => {
this.timeout(5000);

delete process.env['AZP_BASHV3_OLD_SOURCE_BEHAVIOR'];
let tp: string = path.join(__dirname, 'L0Inline.js');
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

Expand All @@ -35,6 +36,30 @@ describe('Bash Suite', function () {
it('Runs a checked in script correctly', (done: MochaDone) => {
this.timeout(5000);

delete process.env['AZP_BASHV3_OLD_SOURCE_BEHAVIOR'];
let tp: string = path.join(__dirname, 'L0External.js');
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

runValidations(() => {
assert(tr.succeeded, 'Bash should have succeeded.');
assert(tr.stderr.length === 0, 'Bash should not have written to stderr');
if (process.platform === 'win32') {
// This is different on windows because we change the script name to make sure the normalization call is happening.
assert(tr.stdout.indexOf(`Writing bash 'temp/path/script' to temp/path/fileName.sh`) > 0, 'Bash should have written the script to a file');
} else {
assert(tr.stdout.indexOf(`Writing bash 'path/to/script' to temp/path/fileName.sh`) > 0, 'Bash should have written the script to a file');
}

assert(tr.stdout.indexOf('my script output') > 0,'Bash should have correctly run the script');
}, tr, done);
});

it('Runs a checked in script correctly when using the old behavior', (done: MochaDone) => {
this.timeout(5000);

process.env['AZP_BASHV3_OLD_SOURCE_BEHAVIOR'] = "true";
let tp: string = path.join(__dirname, 'L0External.js');
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

Expand All @@ -57,6 +82,7 @@ describe('Bash Suite', function () {
it('Adds arguments to the script', (done: MochaDone) => {
this.timeout(5000);

delete process.env['AZP_BASHV3_OLD_SOURCE_BEHAVIOR'];
let tp: string = path.join(__dirname, 'L0Args.js');
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

Expand All @@ -67,14 +93,27 @@ describe('Bash Suite', function () {
assert(tr.stderr.length === 0, 'Bash should not have written to stderr');
if (process.platform === 'win32') {
// This is different on windows because we change the script name to make sure the normalization call is happening.
assert(tr.stdout.indexOf(`Writing . 'temp/path/script' myCustomArg to temp/path/fileName.sh`) > 0, 'Bash should have written the script to a file');
assert(tr.stdout.indexOf(`Writing bash 'temp/path/script' myCustomArg to temp/path/fileName.sh`) > 0, 'Bash should have written the script to a file');
} else {
assert(tr.stdout.indexOf(`Writing . 'path/to/script' myCustomArg to temp/path/fileName.sh`) > 0, 'Bash should have written the script to a file');
assert(tr.stdout.indexOf(`Writing bash 'path/to/script' myCustomArg to temp/path/fileName.sh`) > 0, 'Bash should have written the script to a file');
}

assert(tr.stdout.indexOf('my script output') > 0,'Bash should have correctly run the script');
}, tr, done);
console.log(tr.stdout);
});

it('Reports stderr correctly', (done: MochaDone) => {
this.timeout(5000);

let tp: string = path.join(__dirname, 'L0StdErr.js');
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

runValidations(() => {
assert(tr.failed, 'Bash should have failed');
assert(tr.stdout.indexOf('##vso[task.issue type=error;]myErrorTest') > 0, 'Bash should have correctly written myErrorTest');
}, tr, done);
});
});
3 changes: 2 additions & 1 deletion Tasks/BashV3/Tests/L0Args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'path/to/script': {
isFile() {
return true;
}
},
mode: '777'
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion Tasks/BashV3/Tests/L0External.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'path/to/script': {
isFile() {
return true;
}
},
mode: '777'
}
}
};
Expand Down
67 changes: 67 additions & 0 deletions Tasks/BashV3/Tests/L0StdErr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'bash.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tmr.setInput('targetType', 'inline');
tmr.setInput('workingDirectory', '/fakecwd');
tmr.setInput('script', `>&2 echo "myErrorTest"`);
tmr.setInput('failOnStderr', 'true');

//Create assertAgent and getVariable mocks, support not added in this version of task-lib
const tl = require('azure-pipelines-task-lib/mock-task');
const tlClone = Object.assign({}, tl);
tlClone.getVariable = function(variable: string) {
if (variable.toLowerCase() == 'agent.tempdirectory') {
return 'temp/path';
}
return null;
};
tlClone.assertAgent = function(variable: string) {
return;
};
tmr.registerMock('azure-pipelines-task-lib/mock-task', tlClone);

// Mock task-lib
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
'checkPath' : {
'/fakecwd' : true,
'path/to/bash': true,
'temp/path': true
},
'which': {
'bash': 'path/to/bash'
},
'assertAgent': {
'2.115.0': true
},
'exec': {
'path/to/bash --noprofile --norc -c pwd': {
"code": 0,
"stdout": "temp/path"
},
'path/to/bash temp/path/fileName.sh': {
"code": 0,
"stdout": "",
"stderr": "myErrorTest"
}
}
};
tmr.setAnswers(a);

// Mock fs
const fs = require('fs');
const fsClone = Object.assign({}, fs);
fsClone.writeFileSync = function(filePath, contents, options) {
console.log(`Writing ${contents} to ${filePath}`);
}
tmr.registerMock('fs', fsClone);

// Mock uuidv4
tmr.registerMock('uuid/v4', function () {
return 'fileName';
});

tmr.run();
43 changes: 39 additions & 4 deletions Tasks/BashV3/bash.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs = require('fs');
import path = require('path');
import os = require('os');
import tl = require('azure-pipelines-task-lib/task');
import tr = require('azure-pipelines-task-lib/toolrunner');
var uuidV4 = require('uuid/v4');
Expand Down Expand Up @@ -45,8 +44,10 @@ async function run() {
let input_filePath: string;
let input_arguments: string;
let input_script: string;
let old_source_behavior: boolean;
let input_targetType: string = tl.getInput('targetType') || '';
if (input_targetType.toUpperCase() == 'FILEPATH') {
old_source_behavior = !!process.env['AZP_BASHV3_OLD_SOURCE_BEHAVIOR'];
input_filePath = tl.getPathInput('filePath', /*required*/ true);
if (!tl.stats(input_filePath).isFile()) {
throw new Error(tl.loc('JS_InvalidFilePath', input_filePath));
Expand All @@ -72,7 +73,26 @@ async function run() {
targetFilePath = input_filePath;
}

contents = `. '${targetFilePath.replace("'", "'\\''")}' ${input_arguments}`.trim();
// Choose 1 of 3 behaviors:
// If they've set old_source_behavior, source the script. This is what we used to do and needs to hang around forever for back compat reasons
// If the executable bit is set, execute the script. This is our new desired behavior.
// If the executable bit is not set, source the script and warn. The user should either make it executable or pin to the old behavior.
// See https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/bashnote.md
if (old_source_behavior) {
contents = `. '${targetFilePath.replace("'", "'\\''")}' ${input_arguments}`.trim();
} else {
// Check if executable bit is set
const stats: fs.Stats = tl.stats(input_filePath);
// Check file's executable bit.
if ((stats.mode & 1) > 0) {
contents = `bash '${targetFilePath.replace("'", "'\\''")}' ${input_arguments}`.trim();
}
else {
tl.debug(`File permissions: ${stats.mode}`);
tl.warning('Executable bit is not set on target script, sourcing instead of executing. More info at https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/bashnote.md');
contents = `. '${targetFilePath.replace("'", "'\\''")}' ${input_arguments}`.trim();
}
}
console.log(tl.loc('JS_FormattedCommand', contents));
}
else {
Expand Down Expand Up @@ -122,9 +142,21 @@ async function run() {

// Listen for stderr.
let stderrFailure = false;
const aggregatedStderr: string[] = [];
if (input_failOnStderr) {
bash.on('stderr', (data) => {
bash.on('stderr', (data: Buffer) => {
stderrFailure = true;
// Truncate to at most 10 error messages
if (aggregatedStderr.length < 10) {
// Truncate to at most 1000 bytes
if (data.length > 1000) {
aggregatedStderr.push(`${data.toString('utf8', 0, 1000)}<truncated>`);
} else {
aggregatedStderr.push(data.toString('utf8'));
}
} else if (aggregatedStderr.length === 10) {
aggregatedStderr.push('Additional writes to stderr truncated');
}
});
}

Expand All @@ -142,6 +174,9 @@ async function run() {
// Fail on stderr.
if (stderrFailure) {
tl.error(tl.loc('JS_Stderr'));
aggregatedStderr.forEach((err: string) => {
tl.error(err);
});
result = tl.TaskResult.Failed;
}

Expand All @@ -152,4 +187,4 @@ async function run() {
}
}

run();
run();
4 changes: 2 additions & 2 deletions Tasks/BashV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 159,
"Patch": 3
"Minor": 163,
"Patch": 1
},
"releaseNotes": "Script task consistency. Added support for multiple lines and added support for Windows.",
"minimumAgentVersion": "2.115.0",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/BashV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 159,
"Patch": 3
"Minor": 163,
"Patch": 1
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.115.0",
Expand Down
14 changes: 14 additions & 0 deletions Tasks/CmdLineV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ describe('Cmd Suite', function () {
assert(tr.stdout.indexOf('my script output') > 0,'Cmd should have correctly run the script');
}, tr, done);
});

it('Reports stderr correctly', (done: MochaDone) => {
this.timeout(5000);

let tp: string = path.join(__dirname, 'L0StdErr.js');
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

runValidations(() => {
assert(tr.failed, 'Bash should have failed');
assert(tr.stdout.indexOf('##vso[task.issue type=error;]myErrorTest') > 0, 'Bash should have correctly written myErrorTest');
}, tr, done);
});
});
Loading

0 comments on commit 9c55811

Please sign in to comment.