agent icon indicating copy to clipboard operation
agent copied to clipboard

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

Open wesleyw72 opened this issue 2 years ago • 4 comments

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
    • Following the function calls, we get to here 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
    • 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
      • And then into ScriptWrapper 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.

wesleyw72 avatar Dec 01 '21 10:12 wesleyw72

cc: @DoomGerbil

wesleyw72 avatar Dec 01 '21 10:12 wesleyw72

Sorry this has bitten you, we’ll look at getting this to work.

Interestingly, it seems the other hooks take a slightly different approach

There are two different categories of hook at present, agent lifecycle hooks (of which pre-bootstrap is one) that are executed and can be written in any language. And job lifecycle hooks that are sourced and must be written in bash.

I’ll see if I can get this hook to be correctly exec'd on Windows to match the behaviour of Linux.

keithduncan avatar Dec 07 '21 06:12 keithduncan

Hi @keithduncan, is there any update on this issue? Thanks in advance!

filipVisko avatar Mar 31 '22 09:03 filipVisko

:wave: @filipVisko I’m no longer working on this project with Buildkite, I’d encourage you to reach out to your Buildkite account manager :bow:

keithduncan avatar Mar 31 '22 10:03 keithduncan