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

Bash task #4634

Merged
merged 1 commit into from
Jun 23, 2017
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
14 changes: 14 additions & 0 deletions Tasks/Bash/Strings/resources.resjson/en-US/resources.resjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"loc.friendlyName": "Bash",
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?LinkID=613738)",
"loc.description": "Run a Bash script on Mac, Linux, or Windows",
"loc.instanceNameFormat": "Bash Script",
"loc.releaseNotes": "Script task consistency. Added support for multiple lines and added support for Windows.",
"loc.group.displayName.advanced": "Advanced",
"loc.input.label.script": "Script",
"loc.input.label.workingDirectory": "Working Directory",
"loc.input.label.failOnStderr": "Fail on Standard Error",
"loc.input.help.failOnStderr": "If this is true, this task will fail if any errors are written to the StandardError stream.",
"loc.messages.JS_ExitCode": "Bash exited with code '%s'.",
"loc.messages.JS_Stderr": "Bash wrote one or more lines to the standard error stream."
}
67 changes: 67 additions & 0 deletions Tasks/Bash/bash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import fs = require('fs');
import path = require('path');
import os = require('os');
import tl = require('vsts-task-lib/task');
import tr = require('vsts-task-lib/toolrunner');
var uuidV4 = require('uuid/v4');

async function run() {
try {
tl.setResourcePath(path.join(__dirname, 'task.json'));

// Get inputs.
let failOnStderr = tl.getBoolInput('failOnStderr', false);
let script: string = tl.getInput('script', false) || '';
let workingDirectory = tl.getPathInput('workingDirectory', /*required*/ true, /*check*/ true);

// Write the script to disk.
tl.assertAgent('2.115.0');
let tempDirectory = tl.getVariable('agent.tempDirectory');
tl.checkPath(tempDirectory, `${tempDirectory} (agent.tempDirectory)`);
let filePath = path.join(tempDirectory, uuidV4() + '.sh');
await fs.writeFileSync(
filePath,
'\ufeff' + script, // Prepend the Unicode BOM character.
{ encoding: 'utf8' }); // Since UTF8 encoding is specified, node will
// // encode the BOM into its UTF8 binary sequence.

// Create the tool runner.
let bash = tl.tool(tl.which('bash', true))
.arg('--noprofile')
.arg(`--norc`)
.arg(filePath);
let options = <tr.IExecOptions>{
cwd: workingDirectory,
failOnStdErr: false,
errStream: process.stdout, // Direct all output to STDOUT, otherwise the output may appear out
outStream: process.stdout, // of order since Node buffers it's own STDOUT but not STDERR.
ignoreReturnCode: true
};

// Listen for stderr.
let stderrFailure = false;
if (failOnStderr) {
bash.on('stderr', (data) => {
stderrFailure = true;
});
}

// Run bash.
let exitCode: number = await bash.exec(options);

// Fail on exit code.
if (exitCode !== 0) {
tl.setResult(tl.TaskResult.Failed, tl.loc('JS_ExitCode', exitCode));
}

// Fail on stderr.
if (stderrFailure) {
tl.setResult(tl.TaskResult.Failed, tl.loc('JS_Stderr'));
}
}
catch (err) {
tl.setResult(tl.TaskResult.Failed, err.message || 'run() failed');
}
}

run();
File renamed without changes
File renamed without changes
9 changes: 5 additions & 4 deletions Tasks/ShellScript/package.json → Tasks/Bash/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "vsts-tasks-shellscript",
"name": "vsts-tasks-bash",
"version": "1.0.0",
"description": "VSTS ShellScript Task",
"main": "shellscript.js",
"description": "VSTS Bash Task",
"main": "bash.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/Microsoft/vsts-tasks#readme",
"dependencies": {
"vsts-task-lib": "^0.9.20"
"uuid": "^3.0.1",
"vsts-task-lib": "2.0.5"
}
}
75 changes: 75 additions & 0 deletions Tasks/Bash/task.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"id": "6C731C3C-3C68-459A-A5C9-BDE6E6595B5B",
"name": "Bash",
"friendlyName": "Bash",
"description": "Run a Bash script on Mac, Linux, or Windows",
Copy link
Contributor

Choose a reason for hiding this comment

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

"Mac" -> "macOS"
And maybe alphabetical as Linux, macOS, or Windows?

"helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?LinkID=613738)",
"category": "Utility",
"visibility": [
"Build",
"Release"
],
"runsOn": [
"Agent",
"DeploymentGroup"
],
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 120,
"Patch": 0
},
"releaseNotes": "Script task consistency. Added support for multiple lines and added support for Windows.",
"preview": true,
"minimumAgentVersion": "2.115.0",
"instanceNameFormat": "Bash Script",
"groups": [
{
"name": "advanced",
"displayName": "Advanced",
"isExpanded": false
}
],
"inputs": [
{
"name": "script",
"type": "multiLine",
"label": "Script",
"required": true,
"defaultValue": "# Write your commands here\n# Use the Environment input below to map secret variables into environment variables",
"properties": {
"resizable": "true",
"rows": "10",
"maxLength": "5000"
},
"helpMarkDown": ""
},
{
"name": "workingDirectory",
"type": "filePath",
"label": "Working Directory",
"defaultValue": "",
"required": false,
"groupName": "advanced"
},
{
"name": "failOnStderr",
"type": "boolean",
"label": "Fail on Standard Error",
"defaultValue": "false",
"required": false,
"helpMarkDown": "If this is true, this task will fail if any errors are written to the StandardError stream.",
"groupName": "advanced"
}
],
"execution": {
"Node": {
"target": "bash.js",
"argumentFormat": ""
}
},
"messages": {
"JS_ExitCode": "Bash exited with code '%s'.",
"JS_Stderr": "Bash wrote one or more lines to the standard error stream."
}
}
75 changes: 75 additions & 0 deletions Tasks/Bash/task.loc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"id": "6C731C3C-3C68-459A-A5C9-BDE6E6595B5B",
"name": "Bash",
"friendlyName": "ms-resource:loc.friendlyName",
"description": "ms-resource:loc.description",
"helpMarkDown": "ms-resource:loc.helpMarkDown",
"category": "Utility",
"visibility": [
"Build",
"Release"
],
"runsOn": [
"Agent",
"DeploymentGroup"
],
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 120,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"preview": true,
"minimumAgentVersion": "2.115.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
"groups": [
{
"name": "advanced",
"displayName": "ms-resource:loc.group.displayName.advanced",
"isExpanded": false
}
],
"inputs": [
{
"name": "script",
"type": "multiLine",
"label": "ms-resource:loc.input.label.script",
"required": true,
"defaultValue": "# Write your commands here\n# Use the Environment input below to map secret variables into environment variables",
"properties": {
"resizable": "true",
"rows": "10",
"maxLength": "5000"
},
"helpMarkDown": ""
},
{
"name": "workingDirectory",
"type": "filePath",
"label": "ms-resource:loc.input.label.workingDirectory",
"defaultValue": "",
"required": false,
"groupName": "advanced"
},
{
"name": "failOnStderr",
"type": "boolean",
"label": "ms-resource:loc.input.label.failOnStderr",
"defaultValue": "false",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failOnStderr",
"groupName": "advanced"
}
],
"execution": {
"Node": {
"target": "bash.js",
"argumentFormat": ""
}
},
"messages": {
"JS_ExitCode": "ms-resource:loc.messages.JS_ExitCode",
"JS_Stderr": "ms-resource:loc.messages.JS_Stderr"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"loc.input.label.workingDirectory": "Working Directory",
"loc.input.label.failOnStderr": "Fail on Standard Error",
"loc.input.help.failOnStderr": "If this is true, this task will fail if any errors are written to the StandardError stream.",
"loc.messages.JS_Stderr": "bash wrote one or more lines to the standard error stream.",
"loc.messages.JS_ExitCode": "bash exited with code '%s'.",
"loc.messages.PS_ExitCode": "cmd.exe exited with code '{0}'.",
"loc.messages.JS_ExitCode": "Bash exited with code '%s'.",
"loc.messages.JS_Stderr": "Bash wrote one or more lines to the standard error stream.",
"loc.messages.PS_ExitCode": "Cmd.exe exited with code '{0}'.",
"loc.messages.PS_UnableToDetermineExitCode": "Unexpected exception. Unable to determine the exit code from cmd.exe."
}
27 changes: 0 additions & 27 deletions Tasks/CmdLine/cmdlinetask.ts

This file was deleted.

6 changes: 3 additions & 3 deletions Tasks/CmdLine/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
}
},
"messages": {
"JS_Stderr": "bash wrote one or more lines to the standard error stream.",
"JS_ExitCode": "bash exited with code '%s'.",
"PS_ExitCode": "cmd.exe exited with code '{0}'.",
"JS_ExitCode": "Bash exited with code '%s'.",
"JS_Stderr": "Bash wrote one or more lines to the standard error stream.",
"PS_ExitCode": "Cmd.exe exited with code '{0}'.",
"PS_UnableToDetermineExitCode": "Unexpected exception. Unable to determine the exit code from cmd.exe."
}
}
2 changes: 1 addition & 1 deletion Tasks/CmdLine/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
}
},
"messages": {
"JS_Stderr": "ms-resource:loc.messages.JS_Stderr",
"JS_ExitCode": "ms-resource:loc.messages.JS_ExitCode",
"JS_Stderr": "ms-resource:loc.messages.JS_Stderr",
"PS_ExitCode": "ms-resource:loc.messages.PS_ExitCode",
"PS_UnableToDetermineExitCode": "ms-resource:loc.messages.PS_UnableToDetermineExitCode"
}
Expand Down

This file was deleted.

Loading