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

Only split "commands" on semicolon #7192

Merged
merged 2 commits into from
May 14, 2018
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
8 changes: 6 additions & 2 deletions Tasks/SshV0/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '#!';
Expand Down
29 changes: 12 additions & 17 deletions Tasks/SshV0/ssh2helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,29 @@ export function setupSshClientConnection(sshConfig: any) : Q.Promise<any> {
* @returns {Promise<string>|Promise<T>}
*/
export function runCommandOnRemoteMachine(command: string, sshClient: any, options: RemoteCommandOptions) : Q.Promise<string> {
var defer = Q.defer<string>();
var stdErrWritten:boolean = false;
const defer = Q.defer<string>();
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');
Expand All @@ -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);
}
});
Expand Down
2 changes: 1 addition & 1 deletion Tasks/SshV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for this change to break existing build definitions? Could a user be relying on wrong behavior? If so, we may want to bump the major version number.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe so. If the user is executing a script file and then passing in more commands in the "Arguments" field to be run after the script, they should just put the commands in the script.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about it, I think it is better to not break major version here. There is a way to unblock users relying on this behavior but that would be strange.

"Minor": 121,
"Minor": 135,
"Patch": 0
},
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/SshV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 121,
"Minor": 135,
"Patch": 0
},
"demands": [],
Expand Down