-
Notifications
You must be signed in to change notification settings - Fork 11
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
Adds condition based on build description #129
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...epanik/jenkins/buildhistorymanager/descriptors/conditions/BuildDescriptionDescriptor.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,39 @@ | ||
package pl.damianszczepanik.jenkins.buildhistorymanager.descriptors.conditions; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import hudson.util.ListBoxModel; | ||
import org.jenkinsci.Symbol; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.Messages; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions.BuildDescriptionCondition; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions.BuildDescriptionCondition.MatchingMethodType; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions.Condition; | ||
|
||
/** | ||
* Descriptor implementation needed to render UI for {@link BuildDescriptionCondition}. | ||
* | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
*/ | ||
@Extension | ||
@Symbol("BuildDescription") | ||
public class BuildDescriptionDescriptor extends Descriptor<Condition> { | ||
|
||
public BuildDescriptionDescriptor() { | ||
super(BuildDescriptionCondition.class); | ||
} | ||
|
||
// names must refer to the field name | ||
public ListBoxModel doFillMatchingMethodItems() { | ||
Check warning Code scanning / Jenkins Security Scan Stapler: Missing permission check Warning
Potential missing permission check in BuildDescriptionDescriptor#doFillMatchingMethodItems
|
||
return new ListBoxModel( | ||
// default option should be listed first | ||
new ListBoxModel.Option(Messages.matchingMethodType_EQUALS(), MatchingMethodType.EQUALS.name()), | ||
new ListBoxModel.Option(Messages.matchingMethodType_CONTAINS(), MatchingMethodType.CONTAINS.name()), | ||
new ListBoxModel.Option(Messages.matchingMethodType_MATCHES(), MatchingMethodType.MATCHES.name()) | ||
); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Build description"; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildDescriptionCondition.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,67 @@ | ||
package pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions; | ||
|
||
import hudson.Util; | ||
import hudson.model.Run; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.model.RuleConfiguration; | ||
|
||
/** | ||
* Matches builds that description is equal, contains or matches given pattern. | ||
* | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
*/ | ||
public class BuildDescriptionCondition extends Condition { | ||
|
||
/** | ||
* Matches method for the pattern | ||
*/ | ||
public enum MatchingMethodType { | ||
EQUALS, | ||
CONTAINS, | ||
MATCHES; | ||
} | ||
|
||
private String pattern; | ||
|
||
private MatchingMethodType matchingMethod = MatchingMethodType.EQUALS; | ||
|
||
@DataBoundConstructor | ||
public BuildDescriptionCondition() { | ||
// Jenkins stapler requires to have public constructor with @DataBoundConstructor | ||
} | ||
|
||
public String getPattern() { | ||
return pattern; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setPattern(String pattern) { | ||
this.pattern = Util.fixNull(pattern); | ||
} | ||
|
||
public String getMatchingMethod() { | ||
return matchingMethod.name(); | ||
} | ||
|
||
@DataBoundSetter | ||
public void setMatchingMethod(String matchingMethod) { | ||
this.matchingMethod = MatchingMethodType.valueOf(matchingMethod); | ||
} | ||
|
||
@Override | ||
public boolean matches(Run<?, ?> run, RuleConfiguration configuration) { | ||
// by default build description is null | ||
String buildDescription = Util.fixNull(run.getDescription()); | ||
|
||
switch (matchingMethod) { | ||
case CONTAINS: | ||
return buildDescription.contains(pattern); | ||
case MATCHES: | ||
return buildDescription.matches(pattern); | ||
case EQUALS: | ||
default: // any unspecified value should be fallback to default one -> equals | ||
return buildDescription.equals(pattern); | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...panik/jenkins/buildhistorymanager/model/conditions/BuildDescriptionCondition/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,13 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
|
||
<f:entry | ||
title="Description matching method" | ||
field="matchingMethod"> | ||
<f:select/> | ||
</f:entry> | ||
<f:entry title="Pattern" field="pattern"> | ||
<f:textbox/> | ||
</f:entry> | ||
|
||
</j:jelly> |
12 changes: 12 additions & 0 deletions
12
...czepanik/jenkins/buildhistorymanager/model/conditions/BuildDescriptionCondition/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,12 @@ | ||
<p><b>Description</b></p> | ||
<p>Matches builds that description is equal, contains or matches given pattern.</p> | ||
|
||
<p><b>Use cases</b></p> | ||
<p>Helpful when build description contains text that can be used for decision what to do with the build.</p> | ||
|
||
<p><b>Warning!</b></p> | ||
<p>Leaving <i>pattern</i> field empty makes this condition valid for all builds that have undefined or empty build what | ||
is default value for new created builds.</p> | ||
<p>Methods <i>equals</i> and <i>contains</i> expect to have plain text pattern. To define proper regular expression | ||
pattern for matching type follow <a href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">the | ||
guideline</a>.</p> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Jenkins Security Scan
Stapler: Missing POST/RequirePOST annotation Warning