From eadb5b21772d703b39033cd76e94d055dd72fa77 Mon Sep 17 00:00:00 2001 From: Rick Liu Date: Fri, 23 Mar 2018 13:51:08 -0700 Subject: [PATCH 1/4] JENKINS-49488: implement any_met_condition flag for PromotionProcess.isMet() When any_met_condition flag is true, any met promotion condition would qualify for promote. --- .../promoted_builds/PromotionProcess.java | 25 ++++++++++++++++--- .../PromotionProcess/process-config.jelly | 5 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java b/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java index 5623c157..b5cb3810 100644 --- a/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java +++ b/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java @@ -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; @@ -90,6 +91,11 @@ public final class PromotionProcess extends AbstractProject buildSteps = new ArrayList(); /*package*/ PromotionProcess(JobPropertyImpl property, String name) { @@ -144,6 +150,7 @@ public void doSetName(String name) { assignedLabel = null; } isVisible = c.getString("isVisible"); + any_met_condition = c.optBoolean("any_met_condition"); save(); } @@ -372,11 +379,21 @@ public Status isMet(AbstractBuild build) { List badges = new ArrayList(); 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); } /** diff --git a/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly b/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly index 7605511d..b3043955 100644 --- a/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly +++ b/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly @@ -41,6 +41,11 @@ + + + + Date: Fri, 17 Aug 2018 10:56:15 -0700 Subject: [PATCH 2/4] Remove invalid logging --- .../java/hudson/plugins/promoted_builds/PromotionProcess.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java b/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java index b5cb3810..3dc979e8 100644 --- a/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java +++ b/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java @@ -379,7 +379,6 @@ public Status isMet(AbstractBuild build) { List badges = new ArrayList(); for (PromotionCondition cond : conditions) { PromotionBadge b = cond.isMet(this, build); - 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); From b2d61fb392289f52ad60c2757b0f0be88c562636 Mon Sep 17 00:00:00 2001 From: Rick Liu Date: Fri, 17 Aug 2018 11:57:59 -0700 Subject: [PATCH 3/4] Change public any_met_condition to private and create getter function for process-config.jelly to use. --- .../hudson/plugins/promoted_builds/PromotionProcess.java | 9 ++++++++- .../PromotionProcess/process-config.jelly | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java b/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java index 3dc979e8..f430a577 100644 --- a/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java +++ b/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java @@ -94,7 +94,7 @@ public final class PromotionProcess extends AbstractProject buildSteps = new ArrayList(); @@ -220,6 +220,13 @@ public List getBuildSteps() { return buildSteps; } + /** + * JENKINS-49488: Provide public getter for any_met_condition + */ + public boolean getAnyMetCondition() { + return any_met_condition; + } + /** * Gets the textual representation of the assigned label as it was entered by the user. * @return Assigned label string diff --git a/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly b/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly index b3043955..6991a08b 100644 --- a/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly +++ b/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly @@ -43,7 +43,7 @@ + checked="${instance.getAnyMetCondition()}"/> Date: Fri, 17 Aug 2018 14:26:32 -0700 Subject: [PATCH 4/4] Rename any_met_condition to anyMetCondition to mett Java convention --- .../promoted_builds/PromotionProcess.java | 16 +++++++++------- .../PromotionProcess/process-config.jelly | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java b/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java index f430a577..ba0d4038 100644 --- a/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java +++ b/src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java @@ -94,7 +94,7 @@ public final class PromotionProcess extends AbstractProject buildSteps = new ArrayList(); @@ -150,7 +150,7 @@ public void doSetName(String name) { assignedLabel = null; } isVisible = c.getString("isVisible"); - any_met_condition = c.optBoolean("any_met_condition"); + anyMetCondition = c.optBoolean("anyMetCondition"); save(); } @@ -221,10 +221,10 @@ public List getBuildSteps() { } /** - * JENKINS-49488: Provide public getter for any_met_condition + * JENKINS-49488: Provide public getter for anyMetCondition */ public boolean getAnyMetCondition() { - return any_met_condition; + return anyMetCondition; } /** @@ -386,12 +386,14 @@ public Status isMet(AbstractBuild build) { List badges = new ArrayList(); for (PromotionCondition cond : conditions) { PromotionBadge b = cond.isMet(this, build); - if (this.any_met_condition) { - if (b!=null) + if (this.anyMetCondition) { + if (b!=null) { badges.add(b); + } } else { - if(b==null) + if(b==null) { return null; + } badges.add(b); } } diff --git a/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly b/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly index 6991a08b..3825e7e5 100644 --- a/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly +++ b/src/main/resources/hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly @@ -41,8 +41,8 @@ - - +