fix regression and add trace in clone for local backend (#2241)

regression of #2017 
close  #2211
This commit is contained in:
6543 2023-08-18 14:26:04 +02:00 committed by GitHub
parent a58e3b9e06
commit 0c282e86e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -86,14 +86,20 @@ func (e *local) execClone(ctx context.Context, step *types.Step, state *workflow
// Prepare command // Prepare command
var cmd *exec.Cmd var cmd *exec.Cmd
if runtime.GOOS == "windows" { if rmCmd != "" {
pwsh, err := exec.LookPath("powershell.exe") // if we have a netrc injected we have to make sure it's deleted in any case after clone was attempted
if err != nil { if runtime.GOOS == "windows" {
return err 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 { } 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.Env = env
cmd.Dir = state.workspaceDir 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 // writeNetRC write a netrc file into the home dir of a given workflow state
func writeNetRC(step *types.Step, state *workflowState) (string, error) { func writeNetRC(step *types.Step, state *workflowState) (string, error) {
if step.Environment["CI_NETRC_MACHINE"] == "" { if step.Environment["CI_NETRC_MACHINE"] == "" {
log.Trace().Msg("no netrc to write")
return "", nil return "", nil
} }
@ -120,6 +127,7 @@ func writeNetRC(step *types.Step, state *workflowState) (string, error) {
rmCmd = fmt.Sprintf("del \"%s\"", file) rmCmd = fmt.Sprintf("del \"%s\"", file)
} }
log.Trace().Msgf("try to write netrc to '%s'", file)
return rmCmd, os.WriteFile(file, []byte(fmt.Sprintf( return rmCmd, os.WriteFile(file, []byte(fmt.Sprintf(
netrcFile, netrcFile,
step.Environment["CI_NETRC_MACHINE"], step.Environment["CI_NETRC_MACHINE"],
@ -177,6 +185,7 @@ func downloadLatestGitPluginBinary(dest string) error {
} }
// download successful // download successful
log.Trace().Msgf("download of 'plugin-git' to '%s' successful", dest)
return nil return nil
} }
} }