Skip to content

Commit 7aa4f67

Browse files
Merge pull request #867 from maryiaCodefresh/maryia-howto-cron
Created skip-test-if-pipeline-is-triggered-with-cron.md
2 parents 9af370f + 8c352cd commit 7aa4f67

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "How To: Skip step if pipeline triggered with Cron"
3+
description:
4+
group: kb
5+
sub-group: articles
6+
toc: true
7+
kb: false
8+
ht: true
9+
common: false
10+
categories: [Pipelines]
11+
support-reviewed: 2023-12-12 MB
12+
---
13+
14+
## Overview
15+
16+
You have a build with multiple triggers and you need to skip a certain step if the pipeline was launched using a Cron trigger.
17+
18+
## Details
19+
20+
### Configure Cron trigger message
21+
22+
In the **Message** field of the Cron trigger configuration settings, set a message, for example, "using cron".
23+
24+
### Implement Conditional Step
25+
26+
Use the `EVENT_MESSAGE` variable in your pipeline steps with a condition as in the following example:
27+
28+
{% raw %}
29+
30+
```yaml
31+
Freestyle:
32+
title: Running alpine image
33+
type: freestyle
34+
arguments:
35+
image: 'quay.io/codefreshplugins/alpine:3.8'
36+
commands:
37+
- echo "Displayed only when triggered by cron"
38+
when:
39+
condition:
40+
all:
41+
validateTriggerType: '"${{EVENT_MESSAGE}}" != "using cron"'
42+
```
43+
44+
{% endraw %}
45+
46+
The condition ensures that specific steps execute only when the pipeline is triggered by Cron, _and_ if the Cron job message differs from the one defined in the Message field (`using cron` in our example).
47+
48+
## Related Items
49+
[Triggers in pipelines]({{site.baseurl}}/docs/pipelines/triggers/)
50+
[Cron trigger event variables]({{site.baseurl}}/docs/pipelines/triggers/cron-triggers/#cron-event-payload)
51+
[Conditional execution of steps]({{site.baseurl}}/docs/pipelines/conditional-execution-of-steps/)
52+
[Freestyle step]({{site.baseurl}}/docs/pipelines/steps/freestyle/)

_docs/pipelines/triggers/cron-triggers.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ There are two parts to creating a Cron trigger in the UI:
7272
1. (Optional) Selecting additional options:
7373
* Git trigger event to simulate when the Cron trigger timer is activated. The pipeline is populated with the information from the Git repo such as the repo URL, branch name, latest commit information, including the date and author of the commit.
7474
* Variables to populate for the build
75-
* Caching, volume resuse and notification behavior to override for the build
75+
* Caching, volume reuse and notification behavior to override for the build
7676

7777

7878

@@ -198,6 +198,9 @@ For example, `@every 1h30m10s` would indicate a schedule that triggers every 1 h
198198
>**NOTE:**
199199
The interval does not take the runtime of the job into account. For example, if a job takes three minutes to run, and it is scheduled to run every five minutes, it will have only two minutes of idle time between each run.
200200

201+
### Conditional triggers for Cron jobs
202+
Take a look at our Knowledge Base how-to: [Skip pipeline step if triggered by Cron job]({{site.baseurl}}/docs/kb/articles/skip-test-if-pipeline-is-triggered-with-cron/).
203+
201204
## Cron triggers with Codefresh CLI
202205

203206
>**NOTE**:

0 commit comments

Comments
 (0)