Search code examples
javabamboobamboo-specs

Disable bamboo script task when env condition is met


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


Solution

  • 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