Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

for loop with java spec task

Edited

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.
Jan 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

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.
Feb 02, 2023 • edited
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

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.
Feb 03, 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