Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bash hooks on windows #636

Merged
merged 9 commits into from
Jan 23, 2018
Merged

Support bash hooks on windows #636

merged 9 commits into from
Jan 23, 2018

Conversation

lox
Copy link
Contributor

@lox lox commented Jan 21, 2018

@keithpitt had a neat suggestion for how to support plugin hooks on windows, which was to use the bash.exe bundled with Git for Windows. This generalizes that and searches for the best option under windows, either batch, powershell or if neither of those exist it uses the bash/sh options.

@lox lox mentioned this pull request Jan 21, 2018
@toolmantim
Copy link
Contributor

Nice!!

@lox lox force-pushed the support-bash-hooks-on-windows branch 2 times, most recently from db1fa1e to 692cd94 Compare January 22, 2018 02:10
@keithpitt
Copy link
Member

Rad! Would this mean our plugins "just work" for the most part then?

@lox
Copy link
Contributor Author

lox commented Jan 22, 2018

Rad! Would this mean our plugins "just work" for the most part then?

Yeah, hopefully :)

@lox
Copy link
Contributor Author

lox commented Jan 22, 2018

# Executing "C:\Users\ContainerAdministrator\AppData\Local\Temp\buildkite-agent-bootstrap-hook-runner-066954642"
--
  | > C:\Program Files\Git\usr\bin\bash.exe -c C:/Users/ContainerAdministrator/AppData/Local/Temp/buildkite-agent-bootstrap-hook-runner-066954642
  | This is an example of a pre-command hook from .buildkite/hooks/pre-command

@lox
Copy link
Contributor Author

lox commented Jan 22, 2018

I'm struggling with this error:

> buildkite-agent pipeline upload
--
  | 2018-01-21 20:06:12 DEBUG  Debug mode enabled
  | 2018-01-21 20:06:12 INFO   Reading pipeline config from STDIN
  | 2018-01-21 20:06:12 FATAL  Config file is empty
  | Exited with error: exit status 1

Any ideas @keithpitt?

@lox
Copy link
Contributor Author

lox commented Jan 22, 2018

Ah, right. It seems to be mistakenly detecting that there is a STDIN.

func (b *Bootstrap) findHookFile(hookDir string, name string) (string, error) {
if runtime.GOOS == "windows" {
// check for windows types first
if p, err := shell.LookPath(name, hookDir, ".BAT;.CMD;.EXE"); err == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately we can't support powershell hooks yet, as need to write a environment hook magic thing for them.

func dirForAgentName(agentName string) string {
badCharsPattern := regexp.MustCompile("[[:^alnum:]]")
return badCharsPattern.ReplaceAllString(agentName, "-")
}

func buildkiteAgentBinary() string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This replaces hardcoded buildkite-agent

@lox lox requested a review from keithpitt January 22, 2018 05:37
@lox lox force-pushed the support-bash-hooks-on-windows branch from b9f5db1 to 820ba8d Compare January 22, 2018 05:40
@lox lox force-pushed the support-bash-hooks-on-windows branch from 820ba8d to 33697a1 Compare January 22, 2018 05:45
@lox lox force-pushed the support-bash-hooks-on-windows branch from d35f0e8 to 59cdbc9 Compare January 22, 2018 06:29
@@ -108,7 +108,7 @@ var AnnotateCommand = cli.Command{

if cfg.Body != "" {
body = cfg.Body
} else if stdin.IsPipe() {
} else if terminal.IsTerminal(int(os.Stdin.Fd())) {
Copy link
Member

Choose a reason for hiding this comment

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

Ah, is this the cross platform way to do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, or at least it let's it be someone else's problem. Our implementation didn't seem to work on Windows, despite it saying it did.

@@ -97,12 +105,11 @@ func newHookScriptWrapper(hookPath string) (*hookScriptWrapper, error) {
"SET > \"" + h.afterEnvFile.Name() + "\"\n" +
"EXIT %" + hookExitStatusEnv + "%"
} else {
script = "#!/bin/bash\n" +
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ditched this shebang, we always invoke these scripts with an interpreter and it was causing problems on windows bash.

Copy link
Member

@keithpitt keithpitt left a comment

Choose a reason for hiding this comment

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

Everything looks good to me 🚀

@lox lox merged commit 204f238 into master Jan 23, 2018
@keithduncan keithduncan deleted the support-bash-hooks-on-windows branch September 22, 2021 03:50
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.

None yet

3 participants