About Conditions in Pipelines
There are two types of conditions:
|
Condition on statuses |
Allows you to add conditions on the status of the jobs. |
|
Condition on environment variables |
Allows you to add conditions on environment variables. |
Conditions do not override the initial behavior of the pipeline. As a reminder:
|
Conditions on Statuses
When creating a condition on the job status, you can modify it and choose between three behaviors:
-
All input jobs succeeded: All input jobs have been successfully executed.
-
All input jobs succeeded or have been skipped: All input jobs have been successfully executed or skipped.
-
At least one input job succeeded: At least one input job has been successfully executed.
By default, the condition is set to the option All input jobs succeeded or have been skipped. |
Regardless of the behavior chosen, a condition on a job status must have at least one successful job in its input to succeed. In this way, the rules for the condition on job statuses are as follows:
Conditions on Environment Variables
Expression and Expected Result
Conditions on environment variables are based on the CEL language.
The only constraint for the expression defining your condition, is to return a Boolean value, either true
or false
.
This result will define the condition as Succeeded
if the Boolean returns true
or as Failed
if the Boolean returns false
.
In other words, the only rule to evaluate a condition on environment variables is to have at least one parent job Succeeded
or Failed
.
The branches after the condition will be executed according to this result, as usual.
true
, and therefore the status Succeeded
on the condition.false
, and therefore the status Failed
on the condition.The Life Cycle of a Condition
Conditions have a life cycle similar to that of Saagie jobs, and can go through the following statuses:
|
|
|
||
|
|
|
||
|
|
|
Syntax Validation
Your syntax condition is checked before saving. If there are syntax errors, warning message(s) appear with details about the error(s).
Hover over the condition in error to display the error message(s). |
Expression Validation
A condition will be in Error
if it encounters a technical problem during its evaluation or if its expression cannot be evaluated correctly.
For example, an expression may be invalid because the CEL functions used, or the types manipulated are incorrect, or because the variables used do not exist or are not accessible in the condition.
You can use your Saagie platform’s GraphQL API to retrieve the logs of the instance of the condition(s) in error. |
CEL Language
The possibilities of the CEL language combined with the variables available in your pipelines give you multiple ways to condition your branches. You can use Boolean logic and various basic CEL functions such as :
-
Comparison operators:
>
,<
,>=
,=<
,==
,!=
-
Logical AND and OR:
&&
,||
-
Mathematical operations:
+
,-
,*
,/
-
Conversion type operations
-
Functions on durations and timestamps
-
Collection manipulation functions
The variables used in the conditions are environment variables. By nature, they are not typed and are all strings. Do not forget to convert them to the required type if needed. For more information, see the List of Standard Definitions for CEL. |
The expression now()
returns the current date and a google.protobuf.Timestamp
type, allowing you to use CEL methods on timestamps, such as now().getDayOfMonth() < 15
.
This expression will be true
if the current date is below 15.
Usable Variables
You can use all the existing scopes of environment variables, that is, project, global, and pipeline environment variables.
In addition, if your pipeline has the Variables setting enabled, you will be able to use dynamic variables, that is, output variables modified or created in the jobs preceding the condition, as follows:
-
VARIABLE_NAME
: Corresponds to the last value written by the previous job. -
INIT_VARIABLE_NAME
: Corresponds to the pipeline initialization value, that is, the value of the corresponding environment variable readable by the pipeline. -
jobAlias_VARIABLE_NAME
: Corresponds to the output value written by the job referenced by the job alias.
Variables will be retrieved by the condition during pipeline execution. You can view a summary table of all the input variables for the condition. Click See Variables from the context menu of the condition to display the table.
|