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/pipelines/hooks.md
+40-4Lines changed: 40 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ redirect_from:
7
7
toc:true
8
8
---
9
9
10
-
Hooks in pipelines allow you to run specific actions at the end and the beginning of the pipeline, as well as before/after a step.
10
+
Hooks in pipelines allow you to run specific actions at the end and the beginning of the pipeline, as well as before orafter a step.
11
11
12
12
Hooks can be a[freestyle step]({{site.baseurl}}/docs/pipelines/steps/freestyle/), as you need to define:
13
13
@@ -163,7 +163,7 @@ It is possible to define all possible hooks (`on_elected`, `on_finish`, `on_succ
163
163
164
164
You can also define hooks for individual steps inside a pipeline. This capability allows you to enforce more granular control on defining prepare/cleanup phases for specific steps.
165
165
166
-
The syntax for step hooks is the same as pipeline hooks:`on_elected`,`on_finish`,`on_success`,`on_fail`. The only difference is that you need to add the respective segment within a step instead of the at the root of the pipeline.
166
+
The syntax for step hooks is the same as pipeline hooks:`on_elected`,`on_finish`,`on_success`,`on_fail`. The only difference is that you need to add the respective segment within a step instead of the at the root of the pipeline.
167
167
168
168
For example, this pipeline will always run a cleanup step after integration tests (even if the tests themselves fail).
169
169
@@ -450,6 +450,40 @@ steps:
450
450
451
451
You can use multiple steps in a hook in both the pipeline and the step level.
However, you can add hooks to any other step type, even if the step is nested within a parallel step, as in the example below.
457
+
458
+
```yaml
459
+
460
+
version:"1.0"
461
+
steps:
462
+
root_parallel_step:
463
+
type:parallel
464
+
steps:
465
+
child_step_a:
466
+
image:alpine
467
+
commands:
468
+
-exit 0
469
+
hooks:
470
+
on_finish:
471
+
exec:
472
+
image:alpine
473
+
commands:
474
+
-echo "✅ This is a hook in the 'child_step_a' step nested within 'root_parallel_step'. The hook will work because 'child_step_a' is a 'freestyle' step"
475
+
child_step_b:
476
+
image:alpine
477
+
commands:
478
+
-exit 0
479
+
hooks:
480
+
on_finish:
481
+
exec:
482
+
image:alpine
483
+
commands:
484
+
-echo "✅ This is a hook in the `child_step_b' step which is also nested within 'root_parallel_step'. The hook will work because 'child_step_b' is a 'freestyle' step"
485
+
```
486
+
453
487
### Referencing the 'working_directory' in step hooks
454
488
To access the [`working_directory`]({{site.baseurl}}/docs/pipelines/what-is-the-codefresh-yaml/#working-directories) of a regular step through a hook, use the prefix `parentSteps.<step-name>` For example, to access the `working_directory` of the `clone` step, use {% raw %} `${{parentSteps.clone}}` {% endraw %}.
455
489
@@ -614,12 +648,14 @@ hooks:
614
648
{% endraw %}
615
649
{% endhighlight %}
616
650
651
+
652
+
653
+
617
654
## Limitations of pipeline/step hooks
618
655
619
-
With thecurrent implementation of hooks,the following limitations are present:
656
+
Thecurrent implementation of hooks hasthe following limitations:
620
657
621
658
* The [debugger]({{site.baseurl}}/docs/pipelines/debugging-pipelines/) cannot inspect commands inside hook segments.
622
-
* Hooks are not supported for[parallel steps]({{site.baseurl}}/docs/pipelines/advanced-workflows/).
623
659
* Storage integrations don't resolve in hooks (for example, [test reports]({{site.baseurl}}/docs/testing/test-reports/#producing-allure-test-reports-from-codefresh-pipelines)).