-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e34dcd
commit 577071b
Showing
5 changed files
with
82 additions
and
14 deletions.
There are no files selected for viewing
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,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(); |
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
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