Condition

Condition is the 'when' you want to update

Description

A "condition" stage defines if the "Target" stage stage of a pipeline should be executed or not. It runs a check (depending on the resource kind) that return 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

NameTypeDescriptionRequired
dependsonarraydependson specifies which resources must be executed before the current one
disablesourceinputboolean
failwhenboolean
kindstringkind specifies the conditions resource kind
namestringname specifies the resource name
scmidstringscmid specifies the scm configuration key associated to the current resource
sourceidstring
specobjectspec specifies parameters for a specific conditions kind
transformersarraytransformers defines how the default input value need to be transformed
    addprefixstringAddPrefix adds a prefix to the transformer input value
    addsuffixstringAddSuffix adds a suffix to the transformer input value
    findstringFind searches for a specific value if it exists and return false if it doesn't
    findsubmatchobjectFind searches for a specific value if it exists then return the value using regular expression[pattern]
    replacerobjectReplacer specifies what value needs to be changed and how[from to]
    replacersarrayReplacers specifies a list of replacer instruction
    semverincstringSemvVerInc specifies a comma separated list semantic versioning component that needs to be upgraded.
    trimprefixstringTrimPrefix removes a prefix to the transformer input value
    trimsuffixstringTrimSuffix 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
  • Example checking if a Docker Image is published on 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 are not 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
Top