Skip to content

Commit

Permalink
fix regression and add trace in clone for local backend (#2241)
Browse files Browse the repository at this point in the history
regression of #2017 
close  #2211
  • Loading branch information
6543 authored Aug 18, 2023
1 parent a58e3b9 commit 0c282e8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pipeline/backend/local/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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"],
Expand Down Expand Up @@ -177,6 +185,7 @@ func downloadLatestGitPluginBinary(dest string) error {
}

// download successful
log.Trace().Msgf("download of 'plugin-git' to '%s' successful", dest)
return nil
}
}
Expand Down

0 comments on commit 0c282e8

Please sign in to comment.