-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Bash task #4634
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
Tasks/Bash/Strings/resources.resjson/en-US/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
"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." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
Tasks/ShellScript/Strings/resources.resjson/en-US/resources.resjson
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?