Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bamboo Specs and the reuse of tasks

Jörg Lang July 13, 2021

Hi there,

I'm starting right now to switch from manuelly clicked Build Plans and Deployment Projects to Bamboo Specs.

Especially for the Deployment Projects I have often:

  • multiple environments
  • same tasks for each environment
  • different variable values

Im wondering, if there is any best practise to make the "tasks" reusable because I don't expect that it is the right approach to code the same list of tasks for every environment.

Thanks for given me an hint.

Cheers

Joerg

 

1 answer

1 accepted

1 vote
Answer accepted
Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 13, 2021

Depending of your language of choice Java or YAML it will be different

If we talk about Java, put your tasks to some array and then reuse it

If you plan to use YAML, it has some limitation on repetitive elements usage, but look at https://docs.atlassian.com/bamboo-specs-docs/7.2.4/specs.html?yaml#includes

Jörg Lang July 13, 2021

Hey Alexey,
thanks for you quick answer.

We plan to use Java to avoid any limitation.

Can you please provide a small nippet as an example?

Thanks

Joerg

Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 13, 2021
private static MavenTask maven3Task(String label) {
return new MavenTask()
.version3()
.executableLabel(label);
}

public Plan plan() {
return new Plan(new Project().key("Test")).stages(new Stage("Default stage")
.jobs(new Job("Default job", "JOB1").tasks(
maven3Task("Maven 3.0").goal("clean install"),
maven3Task("mvnvm").goal("test")
)));
}
Jörg Lang July 14, 2021

Hey Alexey,
I'm very sorry, but I don't "understand" your solution snippet :/

As an example, the deployment has following tasks

  • ScriptTask() "Stop Service"
  • ScriptTask() "Stop Website"
  • ScriptTask() "Deploy Backend"
  • ScriptTask() "Start Service"
  • ScriptTask() "Start Website"

These 5 tasks belong togehter and need to happen on each of the environments.

Please suggest, thanks.

Joerg

Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 15, 2021
Deployment deployment = new Deployment(new PlanIdentifier("TEST", "TEST"), "My deployment");
Task[] tasks = new Task[] {
new ScriptTask().description("Stop Service").inlineBody("echo 'stop service'"),
new ScriptTask().description("Stop Website").inlineBody("echo 'stop Website'"),
new ScriptTask().description("Deploy Backend").inlineBody("echo 'Deploy Backend'"),
new ScriptTask().description("Start Service").inlineBody("echo 'Start Service'"),
new ScriptTask().description("Start Website").inlineBody("echo 'Start Website'"),
};

deployment.environments(
new Environment("Env 1").tasks(tasks),
new Environment("Env 3").tasks(tasks)
);
Jörg Lang July 15, 2021

And Bamboo says:

cannot find symbol [ERROR]   symbol:   class Task
Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 15, 2021

You need to have 

import com.atlassian.bamboo.specs.api.builders.task.Task;

 at the top of your class, next to other imports like ScriptTask, Deployment, PlanIdentifier etc

Like Steffen Opel _Utoolity_ likes this
Jörg Lang July 15, 2021

Thanks a lot, that worked now.

For any reason, the IntelliJ has stopped intellisense and import suggestion.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events