How to execute multiple external process from within the same Bamboo task

I need to perform multiple executions of an external process within the same Bamboo task. I've written plugins using code similar to the below. If I want to execute multiple external processes, is there a way to combine the results that each process returns? Does anyone know of any plugins that currently do anything similar to this?

 

public TaskResult execute(final TaskContext taskContext) throws TaskException {
        TaskResultBuilder builder = TaskResultBuilder.create(taskContext);
         
        ExternalProcess process = processService.createProcess(taskContext,
                new ExternalProcessBuilder()
                .command(Arrays.asList("/bin/ls"))
                .workingDirectory(taskContext.getWorkingDirectory()));
 
        process.execute();
        // TODO -- need to execute second process
        // TODO -- need to check the results of both processes
        return builder.checkReturnCode(process, 0).build();
    }

1 answer

I looks like you can check the TaskState of the TaskResultBuilder between ExternalProcess executions.  There are probably more elegant ways to do this, but the following code snippet achieves what I was looking for.

builder = builder.checkReturnCode(process, 0);
        
if(builder.getTaskState() == TaskState.ERROR){
   buildLogger.addErrorLogEntry("Task state == error.  Bombing out...");
   return builder.build();
} else if(builder.getTaskState() == TaskState.FAILED){
   buildLogger.addErrorLogEntry("Task state == failed.  Bombing out...");
   return builder.build();
} else {
   buildLogger.addBuildLogEntry("Process succeeded.  Do something else.");
}

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,067 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot