-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import self promotions from promoted-builds plugin
- Loading branch information
Showing
7 changed files
with
246 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/org/cloudbees/literate/jenkins/promotions/SelfPromotionBadge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2011-2014, CloudBees, Inc., Vincent Latombe | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.cloudbees.literate.jenkins.promotions; | ||
|
||
/** | ||
* Indicates that the promotion was automatically done by {@link org.cloudbees.literate.jenkins.promotions.conditions.SelfPromotionCondition}. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public class SelfPromotionBadge extends PromotionBadge { | ||
} |
118 changes: 118 additions & 0 deletions
118
...ain/java/org/cloudbees/literate/jenkins/promotions/conditions/SelfPromotionCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2011-2014, CloudBees, Inc., Vincent Latombe | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.cloudbees.literate.jenkins.promotions.conditions; | ||
|
||
import hudson.Extension; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.Result; | ||
import hudson.model.TaskListener; | ||
import hudson.model.listeners.RunListener; | ||
import org.cloudbees.literate.jenkins.LiterateBranchBuild; | ||
import org.cloudbees.literate.jenkins.LiterateBranchProject; | ||
import org.cloudbees.literate.jenkins.promotions.*; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* {@link PromotionCondition} that promotes a build as soon as it's done. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public class SelfPromotionCondition extends PromotionCondition { | ||
private final boolean evenIfUnstable; | ||
|
||
@DataBoundConstructor | ||
public SelfPromotionCondition(boolean evenIfUnstable) { | ||
this.evenIfUnstable = evenIfUnstable; | ||
} | ||
|
||
public boolean isEvenIfUnstable() { | ||
return evenIfUnstable; | ||
} | ||
|
||
@Override | ||
public PromotionBadge isMet(PromotionProject promotionProject, LiterateBranchBuild build) { | ||
if (!build.isBuilding()) { | ||
Result r = build.getResult(); | ||
if ((r == Result.SUCCESS) || (evenIfUnstable && r == Result.UNSTABLE)) { | ||
return new SelfPromotionBadge(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* {@link RunListener} to pick up completions of a build. | ||
* <p/> | ||
* <p/> | ||
* This is a single instance that receives all the events everywhere in the system. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
@Extension | ||
public static final class RunListenerImpl extends RunListener<AbstractBuild<?, ?>> { | ||
public RunListenerImpl() { | ||
super((Class) AbstractBuild.class); | ||
} | ||
|
||
@Override | ||
public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) { | ||
if (build instanceof LiterateBranchBuild) { | ||
LiterateBranchBuild lbb = (LiterateBranchBuild) build; | ||
LiterateBranchProject lbp = lbb.getProject(); | ||
PromotionBranchProperty property = lbp.getBranch().getProperty(PromotionBranchProperty.class); | ||
if (property != null) { | ||
for (PromotionConfiguration c : property.getConfigurations()) { | ||
for (PromotionCondition p : c.getConditions()) { | ||
if (p instanceof SelfPromotionCondition) { | ||
PromotionJobProperty pjp = lbp.getProperty(PromotionJobProperty.class); | ||
if (pjp == null) { | ||
throw new IllegalStateException("This project doesn't have any promotion criteria set"); | ||
} | ||
PromotionProject item = pjp.getItem(c.getName()); | ||
if (item == null) { | ||
throw new IllegalStateException("This project doesn't have the promotion criterion called " + c.getName()); | ||
} | ||
try { | ||
item.considerPromotion(lbb); | ||
} catch (IOException e) { | ||
e.printStackTrace(listener.error("Failed to promote a build")); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Extension | ||
public static final class DescriptorImpl extends PromotionConditionDescriptor { | ||
public String getDisplayName() { | ||
return Messages.SelfPromotionCondition_DisplayName(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/resources/org/cloudbees/literate/jenkins/promotions/SelfPromotionBadge/index.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!-- | ||
~ The MIT License | ||
~ | ||
~ Copyright (c) 2014, Vincent Latombe | ||
~ | ||
~ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
~ of this software and associated documentation files (the "Software"), to deal | ||
~ in the Software without restriction, including without limitation the rights | ||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
~ copies of the Software, and to permit persons to whom the Software is | ||
~ furnished to do so, subject to the following conditions: | ||
~ | ||
~ The above copyright notice and this permission notice shall be included in | ||
~ all copies or substantial portions of the Software. | ||
~ | ||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
~ THE SOFTWARE. | ||
--> | ||
<div> | ||
${%Automatically promoted immediately after the build} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
.../org/cloudbees/literate/jenkins/promotions/conditions/SelfPromotionCondition/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!-- | ||
~ The MIT License | ||
~ | ||
~ Copyright (c) 2014, Vincent Latombe | ||
~ | ||
~ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
~ of this software and associated documentation files (the "Software"), to deal | ||
~ in the Software without restriction, including without limitation the rights | ||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
~ copies of the Software, and to permit persons to whom the Software is | ||
~ furnished to do so, subject to the following conditions: | ||
~ | ||
~ The above copyright notice and this permission notice shall be included in | ||
~ all copies or substantial portions of the Software. | ||
~ | ||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
~ THE SOFTWARE. | ||
--> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry> | ||
<f:checkbox name="promotion.self.evenIfUnstable" checked="${instance.evenIfUnstable}"/> | ||
<label class="attach-previous">${%Trigger even if the build is unstable}</label> | ||
</f:entry> | ||
</j:jelly> |
11 changes: 11 additions & 0 deletions
11
...ces/org/cloudbees/literate/jenkins/promotions/conditions/SelfPromotionCondition/help.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div> | ||
Promote a build as soon as a build is completed. This mechanism is convenient for associating | ||
small additional tasks at the end of the build. Compared to making it a part of the build, | ||
the difference is that this makes | ||
the additional step retryable, and a failure will not render the whole build as a failure. | ||
|
||
<p> | ||
This criteria can be also handy for consistency; say you have a lot of components built uniformly, | ||
and many of them have real test jobs hooked up as the downstream promotion criteria, but some of them | ||
might not have any. In such a case, you'll want to immediately promote it. | ||
</div> |
26 changes: 26 additions & 0 deletions
26
...s/org/cloudbees/literate/jenkins/promotions/conditions/SelfPromotionCondition/index.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!-- | ||
~ The MIT License | ||
~ | ||
~ Copyright (c) 2014, Vincent Latombe | ||
~ | ||
~ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
~ of this software and associated documentation files (the "Software"), to deal | ||
~ in the Software without restriction, including without limitation the rights | ||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
~ copies of the Software, and to permit persons to whom the Software is | ||
~ furnished to do so, subject to the following conditions: | ||
~ | ||
~ The above copyright notice and this permission notice shall be included in | ||
~ all copies or substantial portions of the Software. | ||
~ | ||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
~ THE SOFTWARE. | ||
--> | ||
<div> | ||
${%Build failed - cannot be automatically promoted} | ||
</div> |