diff --git a/pipeline/backend/local/clone.go b/pipeline/backend/local/clone.go index e859eb8989..4a76cd26cd 100644 --- a/pipeline/backend/local/clone.go +++ b/pipeline/backend/local/clone.go @@ -86,14 +86,20 @@ func (e *local) execClone(ctx context.Context, step *types.Step, state *workflow // Prepare command var cmd *exec.Cmd - if runtime.GOOS == "windows" { - pwsh, err := exec.LookPath("powershell.exe") - if err != nil { - return err + if rmCmd != "" { + // if we have a netrc injected we have to make sure it's deleted in any case after clone was attempted + if runtime.GOOS == "windows" { + pwsh, err := exec.LookPath("powershell.exe") + if err != nil { + return err + } + cmd = exec.CommandContext(ctx, pwsh, "-Command", fmt.Sprintf("%s ; $code=$? ; %s ; if (!$code) {[Environment]::Exit(1)}", state.pluginGitBinary, rmCmd)) + } else { + cmd = exec.CommandContext(ctx, "/bin/sh", "-c", fmt.Sprintf("%s ; export code=$? ; %s ; exit $code", state.pluginGitBinary, rmCmd)) } - cmd = exec.CommandContext(ctx, pwsh, "-Command", fmt.Sprintf("%s ; $code=$? ; %s ; if (!$code) {[Environment]::Exit(1)}", state.pluginGitBinary, rmCmd)) } else { - cmd = exec.CommandContext(ctx, "/bin/sh", "-c", fmt.Sprintf("%s ; $code=$? ; %s ; exit $code", state.pluginGitBinary, rmCmd)) + // if we have NO netrc, we can just exec the clone directly + cmd = exec.CommandContext(ctx, state.pluginGitBinary) } cmd.Env = env cmd.Dir = state.workspaceDir @@ -110,6 +116,7 @@ func (e *local) execClone(ctx context.Context, step *types.Step, state *workflow // writeNetRC write a netrc file into the home dir of a given workflow state func writeNetRC(step *types.Step, state *workflowState) (string, error) { if step.Environment["CI_NETRC_MACHINE"] == "" { + log.Trace().Msg("no netrc to write") return "", nil } @@ -120,6 +127,7 @@ func writeNetRC(step *types.Step, state *workflowState) (string, error) { rmCmd = fmt.Sprintf("del \"%s\"", file) } + log.Trace().Msgf("try to write netrc to '%s'", file) return rmCmd, os.WriteFile(file, []byte(fmt.Sprintf( netrcFile, step.Environment["CI_NETRC_MACHINE"], @@ -177,6 +185,7 @@ func downloadLatestGitPluginBinary(dest string) error { } // download successful + log.Trace().Msgf("download of 'plugin-git' to '%s' successful", dest) return nil } }