Skip to content

Support PowerShell 7#3759

Draft
markmssd wants to merge 2 commits intobuildkite:mainfrom
markmssd:buildkite-hooks-shell
Draft

Support PowerShell 7#3759
markmssd wants to merge 2 commits intobuildkite:mainfrom
markmssd:buildkite-hooks-shell

Conversation

@markmssd
Copy link

@markmssd markmssd commented Mar 15, 2026

Description

PowerShell 5.1 is the latest supported version, and does not receive any more updates. See https://learn.microsoft.com/en-us/powershell/scripting/install/powershell-support-lifecycle?view=powershell-7.5#windows-powershell-release-history. They now focus on the cross-platform version 7.

Difference between v5 and v7: https://learn.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.5#powershell-executable-changes

Buildkite Agent targets PowerShell 5.1 on Windows, which is convenient because it's always pre-installed on modern Windows. However, it'd be nice to configure it to use PowerShell 7 instead.

Context

Closes #3657

Changes

This PR does a few things to make it work:

  • Look for .ps1 hooks even on non-Windows OS
  • Add a new configuration BUILDKITE_HOOKS_SHELL / --hooks-shell, which works similar to BUILDKITE_SHELL/--shell, but for the Agent Hooks.

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go tool gofumpt -extra -w .)

Disclosures / Credits

@quinn-diesel
Copy link

hey @markmssd just wanted to jump in to confirm that we've got the PR on our list. we've been very swamped this week but we'll have a close look soon for you.

Copy link
Contributor

@DrJosh9000 DrJosh9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @markmssd, this is pretty great!

If you want to add tests, I think it would be fine if you wanted to make some of them Windows-only via t.Skip (there's plenty of precedent), e.g.

func TestSomething_Windows(t *testing.T) {
	if runtime.GOOS != "windows" {
		t.Skip("assumes PowerShell 5 is powershell.exe")
	}
}

rather than trying to fake runtime.GOOS


if commandOverride != "" {
// first element is the command, all others are args to which we append path
commandParts := strings.Fields(commandOverride)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.Fields is close, but we should support the same OS-dependent quoting used for BUILDKITE_SHELL and various other flags, e.g.:

agent/internal/job/executor.go

Lines 1153 to 1157 in 9b50c93

// The interpreter gets parsed based on the operating system
interpreter, err := shellwords.Split(e.Shell)
if err != nil {
return fmt.Errorf("Failed to split shell (%q) into tokens: %w", e.Shell, err)
}

Suggested change
commandParts := strings.Fields(commandOverride)
commandParts, err := shellwords.Split(commandOverride)
if err != nil {
return Command{}, fmt.Errorf("splitting hooks shell %q: %w", commandOverride, err)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--shell does not work for global agent hooks

3 participants