From 7d949b896fda26181b175090e5f2d42a2cd9f7f5 Mon Sep 17 00:00:00 2001 From: PJ Quirk Date: Fri, 11 May 2018 15:42:40 -0400 Subject: [PATCH 1/2] Move split on semicolon to commands parsing --- Tasks/SshV0/ssh.ts | 8 ++++++-- Tasks/SshV0/ssh2helpers.ts | 29 ++++++++++++----------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Tasks/SshV0/ssh.ts b/Tasks/SshV0/ssh.ts index 666684700b42..8dec3637ed30 100644 --- a/Tasks/SshV0/ssh.ts +++ b/Tasks/SshV0/ssh.ts @@ -53,8 +53,12 @@ async function run() { var scriptFile : string; var args : string; - if(runOptions === 'commands') { - commands = tl.getDelimitedInput('commands', '\n', true); + if (runOptions === 'commands') { + // Split on '\n' and ';', flatten, and remove empty entries + commands = tl.getDelimitedInput('commands', '\n', true) + .map(s => s.split(';')) + .reduce((a, b) => a.concat(b)) + .filter(s => s.length > 0); } else if (runOptions === 'inline') { var inlineScript: string = tl.getInput('inline', true); const scriptHeader:string = '#!'; diff --git a/Tasks/SshV0/ssh2helpers.ts b/Tasks/SshV0/ssh2helpers.ts index 9735a780002b..8019dcc3a552 100644 --- a/Tasks/SshV0/ssh2helpers.ts +++ b/Tasks/SshV0/ssh2helpers.ts @@ -52,34 +52,29 @@ export function setupSshClientConnection(sshConfig: any) : Q.Promise { * @returns {Promise|Promise} */ export function runCommandOnRemoteMachine(command: string, sshClient: any, options: RemoteCommandOptions) : Q.Promise { - var defer = Q.defer(); - var stdErrWritten:boolean = false; + const defer = Q.defer(); + let stdErrWritten: boolean = false; - if(!options) { + if (!options) { tl.debug('Options not passed to runCommandOnRemoteMachine, setting defaults.'); - var options = new RemoteCommandOptions(); + options = new RemoteCommandOptions(); options.failOnStdErr = true; } - var cmdToRun = command; - if(cmdToRun.indexOf(';') > 0) { - //multiple commands were passed separated by ; - cmdToRun = cmdToRun.replace(/;/g, '\n'); - } - tl.debug('cmdToRun = ' + cmdToRun); + tl.debug('command = ' + command); - sshClient.exec(cmdToRun, (err, stream) => { - if(err) { - defer.reject(tl.loc('RemoteCmdExecutionErr', err)) + sshClient.exec(command, (err, stream) => { + if (err) { + defer.reject(tl.loc('RemoteCmdExecutionErr', err)); } stream.on('close', (code, signal) => { tl.debug('code = ' + code + ', signal = ' + signal); //based on the options decide whether to fail the build or not if data was written to STDERR - if(stdErrWritten === true && options.failOnStdErr === true) { + if (stdErrWritten && options.failOnStdErr) { defer.reject(tl.loc('RemoteCmdExecutionErr')); - } else if(code && code != 0) { - defer.reject(tl.loc('RemoteCmdNonZeroExitCode', cmdToRun, code)); + } else if (code && code !== 0) { + defer.reject(tl.loc('RemoteCmdNonZeroExitCode', command, code)); } else { //success case - code is undefined or code is 0 defer.resolve('0'); @@ -89,7 +84,7 @@ export function runCommandOnRemoteMachine(command: string, sshClient: any, optio }).stderr.on('data', (data) => { stdErrWritten = true; tl.debug('stderr = ' + data); - if(data && data.toString().trim() !== '') { + if (data && data.toString().trim() !== '') { tl.error(data); } }); From 25b82480bcdda82b24d66641e2e491410d1f1fe0 Mon Sep 17 00:00:00 2001 From: PJ Quirk Date: Mon, 14 May 2018 09:38:15 -0400 Subject: [PATCH 2/2] Updated version --- Tasks/SshV0/task.json | 2 +- Tasks/SshV0/task.loc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tasks/SshV0/task.json b/Tasks/SshV0/task.json index fddceeddb5c3..3efb573803b7 100644 --- a/Tasks/SshV0/task.json +++ b/Tasks/SshV0/task.json @@ -16,7 +16,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 121, + "Minor": 135, "Patch": 0 }, "demands": [], diff --git a/Tasks/SshV0/task.loc.json b/Tasks/SshV0/task.loc.json index 9a33c1f46a53..c8a307b25da7 100644 --- a/Tasks/SshV0/task.loc.json +++ b/Tasks/SshV0/task.loc.json @@ -16,7 +16,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 121, + "Minor": 135, "Patch": 0 }, "demands": [],