You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/en/docs/pipeline-stages/lifecycle-hooks.md
+40-2
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,24 @@ build:
64
64
```
65
65
This config snippet defines that `hook.sh` (for `darwin` or `linux` OS) or `hook.bat` (for `windows` OS) will be executed `before` and `after` each file sync operation for artifact `hooks-example`.
66
66
67
-
### `before-deploy` and `after-deploy` (_to be implemented_)
67
+
### `before-deploy` and `after-deploy` (only for `kubectl` deployer)
68
+
69
+
Example: _skaffold.yaml_ snippet
70
+
```yaml
71
+
deploy:
72
+
kubectl:
73
+
manifests:
74
+
- deployment.yaml
75
+
hooks:
76
+
before:
77
+
- host:
78
+
command: ["sh", "-c", "echo pre-deploy host hook running on $(hostname)!"]
79
+
os: [darwin, linux]
80
+
after:
81
+
- host:
82
+
command: ["sh", "-c", "echo post-deploy host hook running on $(hostname)!"]
83
+
```
84
+
This config snippet defines a simple `echo` command to run before and after each `kubectl` deploy.
68
85
69
86
### Environment variables
70
87
@@ -110,4 +127,25 @@ build:
110
127
```
111
128
This config snippet defines a command to run inside the container corresponding to the artifact `hooks-example` image, `before` and `after` each file sync operation.
112
129
113
-
### `before-deploy` and `after-deploy` (_to be implemented_)
130
+
### `before-deploy` and `after-deploy` (only for `kubectl` deployer)
131
+
132
+
Example: _skaffold.yaml_ snippet
133
+
```yaml
134
+
deploy:
135
+
kubectl:
136
+
manifests:
137
+
- deployment.yaml
138
+
hooks:
139
+
before:
140
+
- container:
141
+
# this will only run when there's a matching container from a previous deploy iteration like in `skaffold dev`
142
+
command: ["sh", "-c", "echo pre-deploy container hook running on $(hostname)!"]
143
+
containerName: hooks-example*
144
+
podName: hooks-example-deployment*
145
+
after:
146
+
- container:
147
+
command: ["sh", "-c", "echo post-deploy container hook running on $(hostname)!"]
148
+
containerName: hooks-example* # use a glob pattern to prefix-match the container name and pod name for deployments, stateful-sets, etc.
149
+
podName: hooks-example-deployment*
150
+
```
151
+
This config snippet defines a simple `echo` command to run inside the containers that match `podName` and `containerName`, before and after each `kubectl` deploy. The `after` container commands are only run post [healthchecks]({{< relref "/docs/workflows/ci-cd.md#waiting-for-skaffold-deployments-using-healthcheck" >}}) on the deployment are complete. Also, unlike the `sync` container hooks, skaffold cannot determine the target container from just the config definition, and needs the `podName` and `containerName`.
0 commit comments