buildkite / buildkite/agent

pre-bootstrap hook doesn't support bash scripts on Windows

Open
#1,540 4 comments 0 reactions 0 assignees View on GitHub
bug hook windows
Dominant language
Go
Stars
1.1k
Forks
378
Avg merge
2d 6h
Merged PRs (30d)
74

Description

We’re trying to make use of the pre-bootstrap hook functionality (on version `3.33.3`) but have hit an interesting issue which we wanted to raise:

## Background:
- We have an agent hooks directory, which we populate with bash scripts to perform our required actions.
Files are named such as:
- `pre-checkout`
- `pre-bootstrap`
- We for the most part (aside from some templating/minor tweaks) use the same hooks across different OSs (Windows, Linux in this case)
- This has worked fine for us so far
- `pre-bootstrap` hooks on Linux works fine

## Issue:
- On Windows agents, the `pre-bootstrap` fails with an error like: `Error: Error building command: exec: "c:\\users\\buildkite-agent\\AppData\\Local\\buildkite-agent\\hooks\\pre-bootstrap": file does not exist`
- We’ve done some digging and it seems that there might be a slightly different code path that gets hit for `pre-bootstrap`.
- `pre-bootstrap` calls `RunWithoutPrompt` [here](https://github.com/buildkite/agent/blob/86d12d8721054d710b13381c0f9d4109dd187a15/agent/job_runner.go#L648)
- Following the function calls, we get to [here](https://github.com/buildkite/agent/blob/86d12d8721054d710b13381c0f9d4109dd187a15/bootstrap/shell/shell.go#L149) where the `PATHEXT` env var is read.
- We don’t do anything special to this env var, so it is the Windows Server 2019 default of `.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC`
- We end up in the LookPath function [here](https://github.com/buildkite/agent/blob/86d12d8721054d710b13381c0f9d4109dd187a15/bootstrap/shell/lookpath_windows.go#L59)
- This checks for executables with one of the extensions above.
- This fails in our case as we have a file called `pre-bootstrap` (bash script) which has none of those extensions.
- Interestingly, it seems the other hooks take a slightly different approach
- They seem to enter executeHook [here](https://github.com/buildkite/agent/blob/86d12d8/bootstrap/bootstrap.go#L344)
- And then into [ScriptWrapper](https://github.com/buildkite/agent/blob/86d12d8/hook/scriptwrapper.go) which seems to handle bash hooks fine.

Hopefully I haven't missed anything. The behaviour took us a bit by surprise, we’d like to have our pre-bootstrap hook script be a bash script that can be used across the platforms.

Contributor guide

Open the contributing guide

Research direction

Start in agent/job_runner.go at the pre-bootstrap RunWithoutPrompt call, then trace bootstrap/shell/shell.go and bootstrap/shell/lookpath_windows.go where PATHEXT is used. Compare this path with bootstrap/bootstrap.go's executeHook and hook/scriptwrapper.go. Done means a bash pre-bootstrap hook without a Windows executable extension runs on Windows while existing hook behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, go
Domain
ci-cd, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.