Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-49488] implement any_met_condition flag for PromotionProcess.isMet() #115

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -90,6 +91,11 @@ public final class PromotionProcess extends AbstractProject<PromotionProcess,Pro
*/
public String isVisible;

/**
* Trigger promotion when any criteria condition is met.
*/
private boolean anyMetCondition;

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

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

Expand Down Expand Up @@ -213,6 +220,13 @@ public List<BuildStep> getBuildSteps() {
return buildSteps;
}

/**
* JENKINS-49488: Provide public getter for anyMetCondition
*/
public boolean getAnyMetCondition() {
return anyMetCondition;
}

/**
* Gets the textual representation of the assigned label as it was entered by the user.
* @return Assigned label string
Expand Down Expand Up @@ -372,11 +386,22 @@ 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);
if (this.anyMetCondition) {
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,11 @@
</select>
</f:entry>

<f:entry title="Any Met">
<f:checkbox name="anyMetCondition" title="${%Trigger promotion when any criteria condition is met}"
checked="${instance.getAnyMetCondition()}"/>
</f:entry>

<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