Disable bamboo script task when env condition is met

336 Views Asked by At

I want one of deployment tasks to be enabled(false) only for ${bamboo.forge.environment.key} = test environment in my bamboo specs config or entire step be skipped if condition is met.

Unfortunately, I'm not Java experienced thus any help will be appreciated.

From documentation it seems that ScriptTask inherits conditions method from Task but from there I got stuck...

    private static ScriptTask runStepFunctions() {
    return new ScriptTask()
            .description("Run Step Function")
            .inlineBody(
                "set -x \n" +
                ....
            )
            .environmentVariables("...")
            .enabled(false)
            .conditions();
}

enter image description here enter image description here

In the end, task should look as below: enter image description here

2

There are 2 best solutions below

0
Oleksiy Chystoprudov On BEST ANSWER

You don't need to be Java expert to find correct snippet for Bamboo plan or deployment configuration. You can configure everything at UI and then use Export to Java Specs or Export to YAML Specs button at deployment project actions button to see how your configuration is translated into code. Then use generated snippet at your Java code

0
marcin2x4 On

As mentioned by Oleksiy:

https://confluence.atlassian.com/bamboo/exporting-existing-plan-configurations-to-bamboo-specs-894743917.html

Generated code:

import com.atlassian.bamboo.specs.api.builders.condition.AnyTaskCondition;
import com.atlassian.bamboo.specs.api.builders.AtlassianModule;
import com.atlassian.bamboo.specs.util.MapBuilder;

//add below method to ScriptTask()
.conditions(new AnyTaskCondition(new AtlassianModule("com.atlassian.bamboo.plugins.bamboo-conditional-tasks:variableCondition"))
                            .configuration(new MapBuilder()
                                    .put("variable", "${forge.environment.key}")
                                    .put("operation", "not_equals")
                                    .put("value", "test")
                                    .build()))