mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-05-09 18:23:21 +08:00
chore: support Multiline SSH commands interpreted as single lines
https://github.com/appleboy/ssh-action/issues/75
This commit is contained in:
parent
77a818a94d
commit
991387fd32
@ -207,11 +207,12 @@ func (p Plugin) scriptCommands() []string {
|
|||||||
commands := make([]string, 0)
|
commands := make([]string, 0)
|
||||||
|
|
||||||
for _, cmd := range scripts {
|
for _, cmd := range scripts {
|
||||||
|
cmd = strings.TrimSpace(cmd)
|
||||||
if strings.TrimSpace(cmd) == "" {
|
if strings.TrimSpace(cmd) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
commands = append(commands, cmd)
|
commands = append(commands, cmd)
|
||||||
if p.Config.ScriptStop {
|
if p.Config.ScriptStop && cmd[(len(cmd)-1):] != "\\" {
|
||||||
commands = append(commands, "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;")
|
commands = append(commands, "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -646,6 +646,17 @@ func TestPlugin_scriptCommands(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: []string{"mkdir a", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir c", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir b", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;"},
|
want: []string{"mkdir a", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir c", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir b", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;"},
|
||||||
},
|
},
|
||||||
|
// See: https://github.com/appleboy/ssh-action/issues/75#issuecomment-668314271
|
||||||
|
{
|
||||||
|
name: "Multiline SSH commands interpreted as single lines",
|
||||||
|
fields: fields{
|
||||||
|
Config: Config{
|
||||||
|
Script: []string{"ls \\ ", "-lah", "mkdir a"},
|
||||||
|
ScriptStop: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []string{"ls \\", "-lah", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;", "mkdir a", "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "trim space",
|
name: "trim space",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
|
Loading…
Reference in New Issue
Block a user