Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-21204] Add ability to boost recently failed Jobs
Added new PriorityStrategy called HealthStrategy
- Loading branch information
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
src/main/java/jenkins/advancedqueue/priority/strategy/HealthStrategy.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,103 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2014, Magnus Sandberg | ||
* | ||
* 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 jenkins.advancedqueue.priority.strategy; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Job; | ||
import hudson.model.Queue; | ||
|
||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
/** | ||
* @author Magnus Sandberg | ||
* @since 2.5 | ||
*/ | ||
public class HealthStrategy extends AbstractStaticPriorityStrategy { | ||
|
||
@Extension | ||
public static class HealthStrategyDescriptor extends AbstractStaticPriorityStrategyDescriptor { | ||
|
||
public HealthStrategyDescriptor() { | ||
super("Using the Jobs Health"); | ||
} | ||
|
||
} | ||
|
||
private String selection; | ||
|
||
private String health; | ||
|
||
@DataBoundConstructor | ||
public HealthStrategy(int priority, String selection, String health) { | ||
setPriority(priority); | ||
this.selection = selection; | ||
this.health = health; | ||
} | ||
|
||
public String getSelection() { | ||
return selection; | ||
} | ||
|
||
public String getHealth() { | ||
return health; | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(Queue.Item item) { | ||
Job<?,?> job = (Job<?,?>) item.task; | ||
if(!job.getBuilds().iterator().hasNext()) { | ||
return false; | ||
} | ||
int score = job.getBuildHealth().getScore(); | ||
int scoreOver = 0; | ||
int scoreUnder = 100; | ||
if("HEALTH_OVER_80".equals(health)) { | ||
scoreOver = 80; | ||
scoreUnder = 100; | ||
} else if("HEALTH_61_TO_80".equals(health)) { | ||
scoreOver = 61; | ||
scoreUnder = 80; | ||
} else if("HEALTH_41_TO_60".equals(health)) { | ||
scoreOver = 41; | ||
scoreUnder = 60; | ||
} else if("HEALTH_21_TO_40".equals(health)) { | ||
scoreOver = 21; | ||
scoreUnder = 40; | ||
} else if("HEALTH_0_TO_20".equals(health)) { | ||
scoreOver = 0; | ||
scoreUnder = 20; | ||
} | ||
if("SAME".equals(selection)) { | ||
return score >= scoreOver && score <= scoreUnder; | ||
} | ||
if("BETTER".equals(selection)) { | ||
return score >= scoreOver; | ||
} | ||
if("WORSE".equals(selection)) { | ||
return score <= scoreUnder; | ||
} | ||
return false; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/resources/jenkins/advancedqueue/priority/strategy/HealthStrategy/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,19 @@ | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:l="/lib/layout" xmlns:st="jelly:stapler"> | ||
<st:include page="config.jelly" class="jenkins.advancedqueue.priority.strategy.AbstractStaticPriorityStrategy" /> | ||
<f:entry title="Scope"> | ||
<select name="selection"> | ||
<f:option value="BETTER" selected="${instance.selection=='BETTER'}">Health is equal or better than</f:option> | ||
<f:option value="SAME" selected="${instance.selection=='SAME'}">Health is exactly</f:option> | ||
<f:option value="WORSE" selected="${instance.selection=='WORSE'}">Health is equal or worse than</f:option> | ||
</select> | ||
<select name="health"> | ||
<!-- Using same naming and conventions as in HealthReport --> | ||
<f:option value="HEALTH_OVER_80" selected="${instance.health=='HEALTH_OVER_80'}">No recent builds failed</f:option> | ||
<f:option value="HEALTH_61_TO_80" selected="${instance.health=='HEALTH_61_TO_80'}">20%-40% of recent builds failed</f:option> | ||
<f:option value="HEALTH_41_TO_60" selected="${instance.health=='HEALTH_41_TO_60'}">40%-60% of recent builds failed</f:option> | ||
<f:option value="HEALTH_21_TO_40" selected="${instance.health=='HEALTH_21_TO_40'}">60%-80% of recent builds failed</f:option> | ||
<f:option value="HEALTH_0_TO_20" selected="${instance.health=='HEALTH_0_TO_20'}">All recent builds failed</f:option> | ||
</select> | ||
</f:entry> | ||
|
||
</j:jelly> |