Condition
Condition is the 'when' you want to update
On this page
Description
A "condition" stage defines whether to run the "Target" stage stage of a pipeline.
It runs a check (depending on the resource kind) that returns a boolean indicating its success (true
) or failure (true
).
Please look at each kind of resource (shell, file, etc.) for details about "how is the success/failure determined?".
Parameters
Name | Type | Description | Required |
---|---|---|---|
dependson | array | "dependson" allows to specify the order of execution of resources It accepts a list of rules like "(resourceType#)resourceId(:booleanOperator)" The resourceType is optional and can be one of "condition", "source" or "target" By default the resourceType is the current resource type The resourceId is the name of the resource to depend on The booleanOperator is optional and can be "AND" or "OR" examples: dependson: - condition#myCondition:and - source#mySource remarks: The parameters "sourceid" and "conditionsids" affect the order of resource execution. To avoid circular dependencies, the depended resource may need to remove any conditionids or set "disablesourceinput to true". | |
disablesourceinput | boolean | ||
failwhen | boolean | ||
kind | string | kind specifies the conditions resource kind | |
name | string | name specifies the resource name | |
scmid | string | scmid specifies the scm configuration key associated to the current resource | |
sourceid | string | ||
spec | object | spec specifies parameters for a specific conditions kind | |
transformers | array | transformers defines how the default input value need to be transformed | |
addprefix | string | AddPrefix adds a prefix to the transformer input value | |
addsuffix | string | AddSuffix adds a suffix to the transformer input value | |
find | string | Find searches for a specific value if it exists and return false if it doesn't | |
findsubmatch | object | Find searches for a specific value if it exists then return the value using regular expression | [pattern] |
replacer | object | Replacer specifies what value needs to be changed and how | [from to] |
replacers | array | Replacers specifies a list of replacer instruction | |
semverinc | string | SemvVerInc specifies a comma separated list semantic versioning component that needs to be upgraded. | |
trimprefix | string | TrimPrefix removes a prefix to the transformer input value | |
trimsuffix | string | TrimSuffix removes the suffix from the transformer input value |
Examples
Example with only 1 source:
sources:
printsName:
kind: shell
spec:
command: echo Ada
conditions:
checkIfFileExistsWithName:
kind: shell
# Implicit instruction (only source)
# sourceID: printsName
spec:
# Should execute the command ""test -f Ada"" (e.g. tests if the file "Ada" exists)
command: test -f
Example with source input disabled:
# Sources defined here
# ...
conditions:
checkIfFileExistsWithName:
kind: shell
disablesourceinput: true
spec:
# Should execute the command "test -f pom.xml" (e.g. tests if the file "pom.xml" exists)
# There are no source value appended
command: test -f pom.xml
This example checks if a Docker Image is published in the registry. It verifies that the docker image
jenkinsciinfra/plugin-site-api
with the tag returned from the source, exists on the DockerHub. The targets of this pipeline aren’t executed if this condition fails.
sources:
tagVersion:
kind: shell
spec:
command: echo v1.0.0
conditions:
IsDockerImagePublished:
name: |
Is the Docker Image
'jenkinsciinfra/plugin-site-api:{{ source `tagVersion` }}
published on the registry?
kind: dockerimage
sourceID: tagVersion
spec:
image: "jenkinsciinfra/plugin-site-api"
# The targets defined below are not executed if
# the image 'jenkinsciinfra/plugin-site-api:v1.0.0'
# is absent on the DockerHub