diff --git a/internal/job/checkout.go b/internal/job/checkout.go index 40fdadd6e1..dcbabc7c94 100644 --- a/internal/job/checkout.go +++ b/internal/job/checkout.go @@ -600,6 +600,7 @@ func (e *Executor) defaultCheckoutPhase(ctx context.Context) error { e.shell.Warningf("Failed to enumerate git submodules: %v", err) } else { mirrorSubmodules := e.ExecutorConfig.GitMirrorsPath != "" + submoduleMirrorDirs := make([]string, 0) for _, repository := range submoduleRepos { submoduleArgs := append([]string(nil), args...) // submodules might need their fingerprints verified too @@ -617,6 +618,8 @@ func (e *Executor) defaultCheckoutPhase(ctx context.Context) error { return fmt.Errorf("getting/updating mirror dir for submodules: %w", err) } + submoduleMirrorDirs = append(submoduleMirrorDirs, mirrorDir) + // Switch back to the checkout dir, doing other operations from GitMirrorsPath will fail. if err := e.createCheckoutDir(); err != nil { return fmt.Errorf("creating checkout dir: %w", err) @@ -642,6 +645,10 @@ func (e *Executor) defaultCheckoutPhase(ctx context.Context) error { } } + for i, dir := range submoduleMirrorDirs { + e.shell.Env.Set(fmt.Sprintf("BUILDKITE_REPO_SUBMODULE_MIRROR_%d", i), dir) + } + if !mirrorSubmodules { args = append(args, "submodule", "update", "--init", "--recursive", "--force") if err := e.shell.Run(ctx, "git", args...); err != nil {