Fix local and ssh backends (#1395)

Base64-encoded string was not decoded.
This commit is contained in:
qwerty287 2022-11-05 13:44:33 +01:00 committed by GitHub
parent a94b756cc4
commit e901f605b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -16,6 +16,7 @@ package local
import ( import (
"context" "context"
"encoding/base64"
"io" "io"
"os" "os"
"os/exec" "os/exec"
@ -69,7 +70,7 @@ func (e *local) Exec(ctx context.Context, step *types.Step) error {
} }
} }
command := []string{} var command []string
if step.Image == constant.DefaultCloneImage { if step.Image == constant.DefaultCloneImage {
// Default clone step // Default clone step
env = append(env, "CI_WORKSPACE="+e.workingdir+"/"+step.Environment["CI_REPO"]) env = append(env, "CI_WORKSPACE="+e.workingdir+"/"+step.Environment["CI_REPO"])
@ -80,9 +81,10 @@ func (e *local) Exec(ctx context.Context, step *types.Step) error {
command = append(command, "-c") command = append(command, "-c")
// TODO: use commands directly // TODO: use commands directly
script := common.GenerateScript(step.Commands) script, _ := base64.StdEncoding.DecodeString(common.GenerateScript(step.Commands))
scriptStr := string(script)
// Deleting the initial lines removes netrc support but adds compatibility for more shells like fish // Deleting the initial lines removes netrc support but adds compatibility for more shells like fish
command = append(command, string(script)[strings.Index(string(script), "\n\n")+2:]) command = append(command, scriptStr[strings.Index(scriptStr, "\n\n")+2:])
} }
// Prepare command // Prepare command

View file

@ -2,6 +2,7 @@ package ssh
import ( import (
"context" "context"
"encoding/base64"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -108,9 +109,10 @@ func (e *ssh) Exec(ctx context.Context, step *types.Step) error {
command = append(command, "-c") command = append(command, "-c")
// TODO: use commands directly // TODO: use commands directly
script := common.GenerateScript(step.Commands) script, _ := base64.StdEncoding.DecodeString(common.GenerateScript(step.Commands))
scriptStr := string(script)
// Deleting the initial lines removes netrc support but adds compatibility for more shells like fish // Deleting the initial lines removes netrc support but adds compatibility for more shells like fish
command = append(command, "cd "+e.workingdir+"/"+step.Environment["CI_REPO"]+" && "+string(script)[strings.Index(string(script), "\n\n")+2:]) command = append(command, "cd "+e.workingdir+"/"+step.Environment["CI_REPO"]+" && "+scriptStr[strings.Index(scriptStr, "\n\n")+2:])
} }
// Prepare command // Prepare command