How To: Skip step if pipeline triggered with Cron
Overview
You have a build with multiple triggers and you need to skip a certain step if the pipeline was launched using a Cron trigger.
Details
Configure Cron trigger message
In the Message field of the Cron trigger configuration settings, set a message, for example, “using cron”.
Implement Conditional Step
Use the EVENT_MESSAGE
variable in your pipeline steps with a condition as in the following example:
Freestyle:
title: Running alpine image
type: freestyle
arguments:
image: 'quay.io/codefreshplugins/alpine:3.8'
commands:
- echo "Displayed only when triggered by cron"
when:
condition:
all:
validateTriggerType: '"${{EVENT_MESSAGE}}" != "using cron"'
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).
Related Items
Triggers in pipelines
Cron trigger event variables
Conditional execution of steps
Freestyle step