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

for loop with java spec task

Robert January 24, 2023

I'm trying to add tasks to a java spec job with a for loop, but there doesn't seem to be an easy way to do it.

I was hoping there was something like

job.addTask(new VcsCheckoutTask().addCheckoutOfDefaultRepository());

 so that I could add tasks from a loop like this

String[] FILES = "${bamboo.REPOS}".split(","); 
for
(int i = 0; i < FILES.length; i++) {
job.addTask(new ScriptTask().fileFromPath(FILES[i]));
}

Any ideas?

1 answer

1 vote
Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 30, 2023
String[] FILES = "${bamboo.REPOS}".split(",");
ScriptTask[] tasks = Arrays.stream(FILES).map(
file -> new ScriptTask().fileFromPath(file)
).toArray(ScriptTask[]::new);

job.tasks(tasks);

By the way, ${bamboo.REPOS} will not be resolved during specs processing. It should be part of your code

Robert February 1, 2023

What if I want to combine different types of tasks like ScriptTask and VcsCheckoutTask into a single job with this method?

How would I pull in a Bamboo global variable if that is not going to be resolved?

Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 2, 2023
Task[] tasks = new Tasks[10];
tasks[0] = new VcsCheckoutTask...
tasks[1] = new ScriptTask....
job.tasks(tasks)

There's no way to pull in Bamboo variables when Bamboo process specs file. You have to keep that variable at your code, not Bamboo. The reason is that you can run specs processing from your workstation with mvn -Ppublish-specs to update Bamboo server configuration without code commit to repository

Robert February 2, 2023

Well then the documentation on Java specs isn’t very clear. Specifically this section regarding variables:

https://docs.atlassian.com/bamboo-specs-docs/9.1.1/specs.html?java#variables

Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 3, 2023

Section about variables you mentioned is about variables available for plans and deployments. 

Variables can be used in configuration fields of tasks

Maybe we should improve it to say that variables are not available for Specs logic. All environment available for Specs is reachable through https://docs.atlassian.com/bamboo-specs-docs/9.1.1/specs.html?java#java-specs-utilities

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events