Skip to content

Commit

Permalink
JENKINS-49488: implement any_met_condition flag for PromotionProcess.…
Browse files Browse the repository at this point in the history
…isMet()

When any_met_condition flag is true,
any met promotion condition would qualify for promote.
  • Loading branch information
Rick Liu committed Mar 24, 2018
1 parent d4557bf commit db9964d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
Expand Down Expand Up @@ -91,6 +92,7 @@ public final class PromotionProcess extends AbstractProject<PromotionProcess,Pro
public String isVisible;

private List<BuildStep> buildSteps = new ArrayList<BuildStep>();
private boolean any_met_condition;

/*package*/ PromotionProcess(JobPropertyImpl property, String name) {
super(property, name);
Expand Down Expand Up @@ -144,6 +146,7 @@ public void doSetName(String name) {
assignedLabel = null;
}
isVisible = c.getString("isVisible");
any_met_condition = c.optBoolean("any_met_condition");
save();
}

Expand Down Expand Up @@ -372,11 +375,21 @@ public Status isMet(AbstractBuild<?,?> build) {
List<PromotionBadge> badges = new ArrayList<PromotionBadge>();
for (PromotionCondition cond : conditions) {
PromotionBadge b = cond.isMet(this, build);
if(b==null)
return null;
badges.add(b);
LOGGER.log(Level.INFO, "PromotionProcess.isMet(): any_met_condition={0}", this.any_met_condition);
if (this.any_met_condition) {
if (b!=null)
badges.add(b);
} else {
if(b==null)
return null;
badges.add(b);
}
}
if (badges.isEmpty()) {
return null;
} else {
return new Status(this,badges);
}
return new Status(this,badges);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
</select>
</f:entry>


<f:checkbox name="any_met_condition" title="${%Trigger when any criteria condition is met}"
checked="${instance.any_met_condition}"/>

<f:optionalBlock name="hasAssignedLabel" title="${%Restrict where this promotion process can be run}"
checked="${instance.assignedLabelString!=null}" inline="true">
<f:entry title="${%Label Expression}"
Expand Down

0 comments on commit db9964d

Please sign in to comment.