Scriptable tasks allow you to dynamically create and execute tasks with different parameters depending on build variables, files changed, etc, using the Bamboo Specs API.

For example, you might use different maven goals depending on the branch, or scp files to different hosts for different staging environments.

The generated task, or tasks, will take the place of the scriptable task.


The way you would work with this typically is first to have the standard task configured, for instance a Maven 3 task, as part of your job. Then add a new task ScriptRunner Scriptable Task. Click the heading Scriptable Task as there is only one type of task in this category.

Rather than writing the code for the task from scratch, click the highlighted link: Copy from other task.

add scriptable task

The dropdown will show you all tasks in all jobs in the current plan. Select the task to generate the code for:

copy task code dlg

On selecting OK the code for the task will be generated and appear in the code editor:

copy task code complete

You can now add conditional logic to change the parameters as you require. You can also paste the code into a file under your script root and use the File tab to point to the .groovy file.

A full example that only adds the deploy task if the branch is master might be:

import com.atlassian.bamboo.variable.CustomVariableContext
import com.atlassian.sal.api.component.ComponentLocator

def variableContext = ComponentLocator.getComponent(CustomVariableContext)
def branchName = variableContext.getVariableContexts().get("planRepository.branchName")?.getValue()

def goals = "clean test"

// if the branch is master, then also deploy
if (branchName == "master") {
    goals += " deploy"

new MavenTask()
    .description("Execute maven goals")

Multiple Tasks

You can also create/execute multiple tasks rather than a simple task. The following trivial example will execute two script tasks:


    new ScriptTask().inlineBody("echo First"),
    new ScriptTask().inlineBody("echo Second"),

Have questions? Visit the Atlassian Community to connect, share, and learn with other Atlassian users and experts, including Adaptavist staff.

Ask a question about ScriptRunner for JIRA, Bitbucket Server, or Confluence.

Want to learn more? Check out courses on Adaptavist Learn, an online platform to onboard and train new users for Atlassian solutions.