Stop builds in the order they are provided from the CLI
@@ -31,8 +31,9 @@ import hudson.model.Item;
import hudson.model.Job;
import hudson.model.Run;
import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -55,7 +56,8 @@ public class StopBuildsCommand extends CLICommand {
@Override
protected int run() throws Exception {
Jenkins jenkins = Jenkins.get();
- final HashSet<String> names = new HashSet<>(jobNames);
+ // Deduplicate job names, but preserve the order specified by the user.
+ final Set<String> names = new LinkedHashSet<>(jobNames);
final List<Job> jobsToStop = new ArrayList<>();
for (final String jobName : names) {
