|
| 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/) |