Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/agent_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type AgentConfiguration struct {
GitCleanFlags string
GitFetchFlags string
GitSubmodules bool
SkipCheckout bool
AllowedRepositories []*regexp.Regexp
AllowedPlugins []*regexp.Regexp
AllowedEnvironmentVariables []*regexp.Regexp
Expand Down
6 changes: 6 additions & 0 deletions agent/job_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,12 @@ BUILDKITE_AGENT_JWKS_KEY_ID`
setEnv("BUILDKITE_PLUGINS_PATH", r.conf.AgentConfiguration.PluginsPath)
setEnv("BUILDKITE_SSH_KEYSCAN", fmt.Sprint(r.conf.AgentConfiguration.SSHKeyscan))
setEnv("BUILDKITE_GIT_SUBMODULES", fmt.Sprint(r.conf.AgentConfiguration.GitSubmodules))
// Allow BUILDKITE_SKIP_CHECKOUT to be enabled either by agent config
// or by pipeline/step env
// This is here now to make it ready for if/when we add skip_checkout to the core app
if r.conf.AgentConfiguration.SkipCheckout {
setEnv("BUILDKITE_SKIP_CHECKOUT", "true")
}
setEnv("BUILDKITE_COMMAND_EVAL", fmt.Sprint(r.conf.AgentConfiguration.CommandEval))
setEnv("BUILDKITE_PLUGINS_ENABLED", fmt.Sprint(r.conf.AgentConfiguration.PluginsEnabled))
// Allow BUILDKITE_PLUGINS_ALWAYS_CLONE_FRESH to be enabled either by config
Expand Down
7 changes: 7 additions & 0 deletions clicommand/agent_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ type AgentStartConfig struct {
GitMirrorsLockTimeout int `cli:"git-mirrors-lock-timeout"`
GitMirrorsSkipUpdate bool `cli:"git-mirrors-skip-update"`
NoGitSubmodules bool `cli:"no-git-submodules"`
SkipCheckout bool `cli:"skip-checkout"`

NoSSHKeyscan bool `cli:"no-ssh-keyscan"`
NoCommandEval bool `cli:"no-command-eval"`
Expand Down Expand Up @@ -624,6 +625,11 @@ var AgentStartCommand = cli.Command{
Usage: "Don't automatically checkout git submodules",
EnvVar: "BUILDKITE_NO_GIT_SUBMODULES,BUILDKITE_DISABLE_GIT_SUBMODULES",
},
cli.BoolFlag{
Name: "skip-checkout",
Usage: "Skip the git checkout phase entirely",
EnvVar: "BUILDKITE_SKIP_CHECKOUT",
},
cli.BoolFlag{
Name: "no-feature-reporting",
Usage: "Disables sending a list of enabled features back to the Buildkite mothership. We use this information to measure feature usage, but if you're not comfortable sharing that information then that's totally okay :)",
Expand Down Expand Up @@ -1040,6 +1046,7 @@ var AgentStartCommand = cli.Command{
GitCleanFlags: cfg.GitCleanFlags,
GitFetchFlags: cfg.GitFetchFlags,
GitSubmodules: !cfg.NoGitSubmodules,
SkipCheckout: cfg.SkipCheckout,
SSHKeyscan: !cfg.NoSSHKeyscan,
CommandEval: !cfg.NoCommandEval,
PluginsEnabled: !cfg.NoPlugins,
Expand Down
7 changes: 7 additions & 0 deletions clicommand/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type BootstrapConfig struct {
AutomaticArtifactUploadPaths string `cli:"artifact-upload-paths"`
ArtifactUploadDestination string `cli:"artifact-upload-destination"`
CleanCheckout bool `cli:"clean-checkout"`
SkipCheckout bool `cli:"skip-checkout"`
GitCheckoutFlags string `cli:"git-checkout-flags"`
GitCloneFlags string `cli:"git-clone-flags"`
GitFetchFlags string `cli:"git-fetch-flags"`
Expand Down Expand Up @@ -227,6 +228,11 @@ var BootstrapCommand = cli.Command{
Usage: "Whether or not the bootstrap should remove the existing repository before running the command",
EnvVar: "BUILDKITE_CLEAN_CHECKOUT",
},
cli.BoolFlag{
Name: "skip-checkout",
Usage: "Skip the git checkout phase entirely",
EnvVar: "BUILDKITE_SKIP_CHECKOUT",
},
cli.StringFlag{
Name: "git-checkout-flags",
Value: "-f",
Expand Down Expand Up @@ -468,6 +474,7 @@ var BootstrapCommand = cli.Command{
CancelSignal: cancelSig,
SignalGracePeriod: signalGracePeriod,
CleanCheckout: cfg.CleanCheckout,
SkipCheckout: cfg.SkipCheckout,
Command: cfg.Command,
CommandEval: cfg.CommandEval,
Commit: cfg.Commit,
Expand Down
5 changes: 5 additions & 0 deletions internal/job/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ func (e *Executor) CheckoutPhase(ctx context.Context) error {

// checkout runs checkout hook or default checkout logic
func (e *Executor) checkout(ctx context.Context) error {
if e.SkipCheckout {
e.shell.Commentf("Skipping checkout, BUILDKITE_SKIP_CHECKOUT is set")
return nil
}

// There can only be one checkout hook, either plugin or global, in that order
switch {
case e.hasPluginHook("checkout"):
Expand Down
20 changes: 20 additions & 0 deletions internal/job/checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ func TestDefaultCheckoutPhase(t *testing.T) {
}
}

func TestSkipCheckout(t *testing.T) {
t.Parallel()

ctx := context.Background()

sh, err := shell.New()
require.NoError(t, err)

executor := &Executor{
shell: sh,
ExecutorConfig: ExecutorConfig{
Repository: "https://github.com/buildkite/agent.git",
SkipCheckout: true,
},
}

err = executor.checkout(ctx)
require.NoError(t, err)
}

func TestDefaultCheckoutPhase_DelayedRefCreation(t *testing.T) {
if race.IsRaceTest {
t.Skip("this test simulates the agent recovering from a race condition, and needs to create one to test it.")
Expand Down
3 changes: 3 additions & 0 deletions internal/job/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type ExecutorConfig struct {
// Should the executor remove an existing checkout before running the job
CleanCheckout bool `env:"BUILDKITE_CLEAN_CHECKOUT"`

// Skip the checkout phase entirely
SkipCheckout bool `env:"BUILDKITE_SKIP_CHECKOUT"`

// Flags to pass to "git checkout" command
GitCheckoutFlags string `env:"BUILDKITE_GIT_CHECKOUT_FLAGS"`

Expand Down
21 changes: 21 additions & 0 deletions internal/job/integration/checkout_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,27 @@ func TestForcingACleanCheckout(t *testing.T) {
}
}

func TestSkippingCheckout(t *testing.T) {
t.Parallel()

tester, err := NewExecutorTester(mainCtx)
if err != nil {
t.Fatalf("NewExecutorTester() error = %v", err)
}
defer tester.Close()

tester.RunAndCheck(t, "BUILDKITE_SKIP_CHECKOUT=true")

if !strings.Contains(tester.Output, "Skipping checkout") {
t.Fatal(`tester.Output does not contain "Skipping checkout"`)
}

// Verify no git commands were run (no clone, fetch, checkout)
if strings.Contains(tester.Output, "git clone") {
t.Fatal(`tester.Output should not contain "git clone" when checkout is skipped`)
}
}

func TestCheckoutOnAnExistingRepositoryWithoutAGitFolder(t *testing.T) {
t.Parallel()

Expand Down