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
* Add syntax for working directory in step hook
Added section for referencing working directoy in step hook and commented out limitation on the same
* Update hooks.md
* Update hooks.md
Added inline xref to working directory section
* Update hooks.md
Added <step-name> to parentSteps syntax
Copy file name to clipboardExpand all lines: _docs/pipelines/hooks.md
+34-42Lines changed: 34 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -161,9 +161,9 @@ It is possible to define all possible hooks (`on_elected`, `on_finish`, `on_succ
161
161
162
162
## Step hooks
163
163
164
-
Hooks can also be defined for individual steps inside a pipeline. This capability allows for more granular control on defining prepare/cleanup phases for specific steps.
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`), you just need to put the respective segment under a step instead of 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
@@ -200,7 +200,7 @@ steps:
200
200
{% endhighlight %}
201
201
202
202
203
-
Logs for steps hooks are shown in the log window of the step itself.
203
+
Logs for steps hooks are displayed in the log window of the step itself.
204
204
205
205
{% include
206
206
image.html
@@ -212,7 +212,7 @@ caption="Hooks before a pipeline"
212
212
max-width="80%"
213
213
%}
214
214
215
-
As with pipeline hooks, it is possible to define multiple hook conditions for each step.
215
+
As with pipeline hooks, you can also define multiple hook conditions for each step.
216
216
217
217
`codefresh.yml`
218
218
{% highlight yaml %}
@@ -254,17 +254,17 @@ steps:
254
254
The order of events in the example above is the following:
255
255
256
256
1. The `on_elected` segment executes first (authentication)
257
-
1. The step itself executes (the security scan)
258
-
1. The `on_fail` segment executes (only if the step throws an error code)
257
+
1. The `Security Scanning`step itself executes the security scan
258
+
1. The `on_fail` segment executes only if the step throws an error code
259
259
1. The `on_finish` segment always executes at the end
260
260
261
261
262
-
## Running steps/plugins in hooks
262
+
###Running steps/plugins in hooks
263
263
264
-
Hooks can use [steps/plugins](https://steps.codefresh.io){:target="\_blank"}. With plugins you have to specify:
265
-
266
-
- The type field for the step/plugin.
267
-
- The arguments needed for the step/plugin.
264
+
Hooks can use [steps/plugins](https://steps.codefresh.io){:target="\_blank"}.
265
+
With plugins you have to specify:
266
+
- The type field for the step/plugin
267
+
- The arguments needed for the step/plugin
268
268
269
269
`codefresh.yml`
270
270
{% highlight yaml %}
@@ -298,13 +298,16 @@ steps:
298
298
{% endraw %}
299
299
{% endhighlight %}
300
300
301
-
## Controlling errors inside pipeline/step hooks
301
+
###Controlling errors inside pipeline/step hooks
302
302
303
-
By default if a step fails within a pipeline, the whole pipeline will stop and be marked as failed.
304
-
This is also true for `on_elected` segments as well. If they fail, then the whole pipeline will fail (regardless of the position of the segment in a pipeline or step). However, this only applies to `on_elected` segments.
305
-
`on_success`, `on_fail` and `on_finish` segments do not affect the pipeline outcome at all, and a pipeline will continue even if one of these segments fails.
303
+
By default, if a step fails within a pipeline, pipeline execution is terminated and the pipeline is marked as failed.
304
+
*`on_elected` segments
305
+
If `on_elected` segments fail, regardless of the position of the segment in a pipeline or step, the whole pipeline will fail.
306
+
*`on_success`, `on_fail` and `on_finish` segments
307
+
`on_success`, `on_fail` and `on_finish` segments do not affect the pipeline outcome. A pipeline will continue execution even if one of these segments fails.
306
308
307
-
For example the following pipeline will fail right away, because the pipeline hook fails at the beginning.
309
+
**Pipeline execution example with `on_elected` segment**
310
+
The following pipeline will fail right away, because the pipeline hook fails at the beginning.
308
311
309
312
`codefresh.yml`
310
313
{% highlight yaml %}
@@ -351,6 +354,7 @@ steps:
351
354
{% endraw %}
352
355
{% endhighlight %}
353
356
357
+
354
358
This pipeline will now execute successfully and `step1` will still run as normal, because we have used the `fail_fast` property. You can also use the `fail_fast` property on step hooks as well:
355
359
356
360
`codefresh.yml`
@@ -379,7 +383,7 @@ steps:
379
383
>Notice that the `fail_fast` property is only available for `on_elected` hooks. The other types of hooks (`on_finish`, `on_success`, `on_fail`) do not affect the outcome of the pipeline in any way. Even if they fail, the pipeline will continue running to completion. This behavior is not configurable.
380
384
381
385
382
-
## Using multiple steps for hooks
386
+
###Using multiple steps for hooks
383
387
384
388
In all the previous examples, each hook was a single step running on a single Docker image. You can also define multiple steps for each hook. This is possible by inserting an extra `steps` keyword inside the hook and listing multiple Docker images under it:
385
389
@@ -445,6 +449,10 @@ steps:
445
449
446
450
You can use multiple steps in a hook in both the pipeline and the step level.
447
451
452
+
### Referencing the 'working_directory' in step hooks
453
+
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 %}.
454
+
455
+
448
456
449
457
## Using annotations and labels in hooks
450
458
@@ -525,9 +533,10 @@ The pipeline is not correct, because the first segment of annotations is directl
525
533
526
534
## Syntactic sugar syntax
527
535
528
-
To simplify the syntax for hooks, the following simplifications are also offered:
536
+
We offer the following options to simplify the syntax for hooks.
529
537
530
-
If you do not want to use metadata or annotations in your hook the keyword `exec` can be omitted:
538
+
**Not using metadata or annotations in your hook**
539
+
Omit the keyword `exec`:
531
540
532
541
`codefresh.yml`
533
542
{% highlight yaml %}
@@ -552,6 +561,7 @@ steps:
552
561
{% endhighlight %}
553
562
554
563
564
+
**Not specify teh Docker image**
555
565
If you do not want to specify the Docker image you can simply omit it. Codefresh will use the `alpine` image in that case to run the hook:
556
566
557
567
@@ -581,25 +591,7 @@ steps:
581
591
{% endhighlight %}
582
592
583
593
584
-
If you don't use metadata or annotations, you can also completely remove the `exec` keyword and just mention the commands you want to run (`alpine` image will be used by default):
585
594
586
-
`codefresh.yml`
587
-
{% highlight yaml %}
588
-
{% raw %}
589
-
version: "1.0"
590
-
hooks:
591
-
on_elected: # no exec/image keyword - alpine image will be used
592
-
- echo "Pipeline starting"
593
-
steps:
594
-
build:
595
-
type: build
596
-
image_name: my_image
597
-
tag: master
598
-
hooks:
599
-
on_success: # no exec/image keyword - alpine image will be used
600
-
- echo "Docker image was built successfully"
601
-
{% endraw %}
602
-
{% endhighlight %}
603
595
604
596
## Using Type Steps / Plugins in hooks
605
597
@@ -625,14 +617,14 @@ hooks:
625
617
626
618
With the current implementation of hooks, the following limitations are present:
627
619
628
-
* The [debugger]({{site.baseurl}}/docs/pipelines/debugging-pipelines/) cannot inspect commands inside hook segments
629
-
* Hooks are not supported for [parallel steps]({{site.baseurl}}/docs/pipelines/advanced-workflows/)
630
-
* Storage integrations don't resolve in hooks (for example, [test reports]({{site.baseurl}}/docs/testing/test-reports/#producing-allure-test-reports-from-codefresh-pipelines))
631
-
* Step hook does not support the working_directory field aka `working_directory: ${{clone}}`
620
+
* The [debugger]({{site.baseurl}}/docs/pipelines/debugging-pipelines/) cannot inspect commands inside hook segments.
621
+
* Hooks are not supported for [parallel steps]({{site.baseurl}}/docs/pipelines/advanced-workflows/).
622
+
* Storage integrations don't resolve in hooks (for example, [test reports]({{site.baseurl}}/docs/testing/test-reports/#producing-allure-test-reports-from-codefresh-pipelines)).
632
623
633
624
## Related articles
634
625
[Conditional execution of steps]({{site.baseurl}}/docs/pipelines/conditional-execution-of-steps/)
0 commit comments