Examples for AddTask Action - Conditional Tasks

Description

Bamboo added the ability to define conditional tasks in Bamboo 7.1. Bamboo provides the ability to condition the task on a variable as a built in capability and enable 3rd parties to contribute additional condition types. No matter what condition you want to do, it is supported by the CLI for Plan Creation Scripting by using the appropriate field values. The variable example below is provided and other condition types can be handled similarly - the user will need to figure out the equivalent fields for those unique capabilities (suggest you add a task manually and then run exportJob to see what is needed in a plan creation script.

Example - Variable Condition Type

FieldExample ValueDescriptionOther Values
conditionTasktrueMake task conditional with true value.false

selectedCondition

com.atlassian.bamboo.plugins.bamboo-conditional-tasks:variableConditionType of condition. This is the built-it variable condition available in Bamboo.Depends on 3rd party or custom apps installed

task.condition.variable.name

exitCodeName of the Bamboo variable that will be used to condition the task.

task.condition.variable.operation

not_equalsOperation used to determine condition based on variable value and compare valueequals, matches (means regex)
task.condition.variable.value.not_equals0Compare value for a not_equals condition check
task.condition.variable.value.equalsN/A when using not_equalsCompare value for a equals condition check

task.condition.variable.value.matches

N/A when using not_equalsMatch regex for a match condition check
CLI action
-a addTask --plan CLI-EXAMPLES --job JOB1 --taskKey SCRIPT --field "scriptBody=..." \
    --field conditionalTask=true \
    --field selectedCondition=com.atlassian.bamboo.plugins.bamboo-conditional-tasks:variableCondition \
    --field task.condition.variable.name=exitCode \
    --field task.condition.variable.operation=not_equals \
    --field task.condition.variable.value.not_equals=0 \

Tips

Queue build with a specific variable setting

Use the CLI queueBuild action to queue a build and set a Bamboo variable used for task conditioning. See How to set plan variables on queueBuild.

Dynamically setting variables

Since task conditioning is based on Bamboo variables, is there a quick way to set a Bamboo variable so it can later be used in conditioning?

The inject Bamboo variables task (see Configuring variables task) will dynamically set job or plan level values for Bamboo variables. This is done through a properties file which can be dynamically created in another task.