Skip to content

Commit 907095e

Browse files
authored
Merge pull request #4807 from Microsoft/users/lukillgo/sshscript
#959233: SSH: add inline script support
2 parents 11ee00a + e845eae commit 907095e

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

Tasks/SSH/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"loc.input.help.commands": "Specify the shell commands to run on the remote machine. Enter each command along with its arguments on a new line. To run multiple commands together, enter them on the same line separated by semi-colons (e.g. cd /home/user/myFolder;build).",
1313
"loc.input.label.scriptPath": "Shell script path",
1414
"loc.input.help.scriptPath": "Path to the shell script file to run on the remote machine.",
15+
"loc.input.label.inline": "Inline Script",
16+
"loc.input.help.inline": "Write the shell script to run on the remote machine.",
1517
"loc.input.label.args": "Arguments",
1618
"loc.input.help.args": "Arguments to pass to the shell script.",
1719
"loc.input.label.failOnStdErr": "Fail on STDERR",

Tasks/SSH/ssh.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ async function run() {
5555

5656
if(runOptions === 'commands') {
5757
commands = tl.getDelimitedInput('commands', '\n', true);
58+
} else if (runOptions === 'inline') {
59+
var inlineScript: string = tl.getInput('inline', true);
60+
const scriptHeader:string = '#!';
61+
if (inlineScript && !inlineScript.startsWith(scriptHeader)) {
62+
const bashHeader: string = '#!/bin/bash';
63+
tl.debug('No script header detected. Adding: ' + bashHeader);
64+
inlineScript = bashHeader + os.EOL + inlineScript;
65+
}
66+
scriptFile = path.join(os.tmpdir(), 'sshscript_' + new Date().getTime()); // default name
67+
try {
68+
fs.writeFileSync(scriptFile, inlineScript);
69+
} catch (err) {
70+
this.deleteFile(scriptFile);
71+
throw err;
72+
}
5873
} else {
5974
scriptFile = tl.getPathInput('scriptPath', true, true);
6075
args = tl.getInput('args')
@@ -83,7 +98,7 @@ async function run() {
8398
commands[i], sshClientConnection, remoteCmdOptions);
8499
tl.debug('Command ' + commands[i] + ' completed with return code = ' + returnCode);
85100
}
86-
} else if (runOptions === 'script') {
101+
} else { // both other runOptions: inline and script
87102
//setup script path on remote machine relative to user's $HOME directory
88103
var remoteScript = './' + path.basename(scriptFile);
89104
var remoteScriptPath = '"' + remoteScript + '"';

Tasks/SSH/task.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"author": "Microsoft Corporation",
1717
"version": {
1818
"Major": 0,
19-
"Minor": 115,
19+
"Minor": 121,
2020
"Patch": 0
2121
},
2222
"demands": [],
@@ -46,7 +46,8 @@
4646
"defaultValue": "commands",
4747
"options": {
4848
"commands": "Commands",
49-
"script": "Shell script"
49+
"script": "Script File",
50+
"inline": "Inline Script"
5051
},
5152
"helpMarkDown": "Choose to either run shell commands or a shell script on the remote machine."
5253
},
@@ -72,6 +73,19 @@
7273
"visibleRule": "runOptions = script",
7374
"helpMarkDown": "Path to the shell script file to run on the remote machine."
7475
},
76+
{
77+
"name": "inline",
78+
"type": "multiLine",
79+
"label": "Inline Script",
80+
"defaultValue": "",
81+
"required": true,
82+
"visibleRule": "runOptions = inline",
83+
"helpMarkDown": "Write the shell script to run on the remote machine.",
84+
"properties": {
85+
"resizable": "true",
86+
"rows": "10"
87+
}
88+
},
7589
{
7690
"name": "args",
7791
"type": "string",

Tasks/SSH/task.loc.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"author": "Microsoft Corporation",
1717
"version": {
1818
"Major": 0,
19-
"Minor": 115,
19+
"Minor": 121,
2020
"Patch": 0
2121
},
2222
"demands": [],
@@ -46,7 +46,8 @@
4646
"defaultValue": "commands",
4747
"options": {
4848
"commands": "Commands",
49-
"script": "Shell script"
49+
"script": "Script File",
50+
"inline": "Inline Script"
5051
},
5152
"helpMarkDown": "ms-resource:loc.input.help.runOptions"
5253
},
@@ -72,6 +73,19 @@
7273
"visibleRule": "runOptions = script",
7374
"helpMarkDown": "ms-resource:loc.input.help.scriptPath"
7475
},
76+
{
77+
"name": "inline",
78+
"type": "multiLine",
79+
"label": "ms-resource:loc.input.label.inline",
80+
"defaultValue": "",
81+
"required": true,
82+
"visibleRule": "runOptions = inline",
83+
"helpMarkDown": "ms-resource:loc.input.help.inline",
84+
"properties": {
85+
"resizable": "true",
86+
"rows": "10"
87+
}
88+
},
7589
{
7690
"name": "args",
7791
"type": "string",

0 commit comments

Comments
 (0)