Skip to content

Commit e1f52f4

Browse files
authored
feat: allow specifying hook command directory (#6982)
1 parent a37f411 commit e1f52f4

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

docs/content/en/schemas/v2beta27.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,11 @@
20912091
"x-intellij-html-description": "command to execute.",
20922092
"default": "[]"
20932093
},
2094+
"dir": {
2095+
"type": "string",
2096+
"description": "specifies the working directory of the command. If empty, the command runs in the calling process's current directory.",
2097+
"x-intellij-html-description": "specifies the working directory of the command. If empty, the command runs in the calling process's current directory."
2098+
},
20942099
"os": {
20952100
"items": {
20962101
"type": "string"
@@ -2103,7 +2108,8 @@
21032108
},
21042109
"preferredOrder": [
21052110
"command",
2106-
"os"
2111+
"os",
2112+
"dir"
21072113
],
21082114
"additionalProperties": false,
21092115
"type": "object",

integration/examples/lifecycle-hooks/skaffold.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ build:
77
before:
88
- command: ["sh", "-c", "./hook.sh"]
99
os: [darwin, linux]
10+
dir: .
1011
- command: ["cmd.exe", "/C", "hook.bat"]
1112
os: [windows]
13+
dir: .
1214
after:
1315
- command: ["sh", "-c", "docker images $SKAFFOLD_IMAGE --digests"]
1416
os: [darwin, linux]

pkg/skaffold/hooks/host.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (h hostHook) retrieveCmd(ctx context.Context, out io.Writer) *exec.Cmd {
5858
cmd.Stderr = out
5959
cmd.Env = append(cmd.Env, h.env...)
6060
cmd.Env = append(cmd.Env, util.OSEnviron()...)
61+
cmd.Dir = h.cfg.Dir
6162

6263
return cmd
6364
}

pkg/skaffold/schema/latest/v1/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,9 @@ type HostHook struct {
14651465
Command []string `yaml:"command" yamltags:"required"`
14661466
// OS is an optional slice of operating system names. If the host machine OS is different, then it skips execution.
14671467
OS []string `yaml:"os,omitempty"`
1468+
// Dir specifies the working directory of the command.
1469+
// If empty, the command runs in the calling process's current directory.
1470+
Dir string `yaml:"dir,omitempty" skaffold:"filepath"`
14681471
}
14691472

14701473
// ContainerHook describes a lifecycle hook definition to execute on a container. The container name is inferred from the scope in which this hook is defined.

0 commit comments

Comments
 (0)