Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added action to the project that contains the email-ext as a publisher which allows the user to enter a template name, select a previous build and see the rendered template.
- Loading branch information
Showing
8 changed files
with
136 additions
and
7 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/main/java/hudson/plugins/emailext/EmailExtTemplateAction.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,65 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package hudson.plugins.emailext; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Action; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.emailext.plugins.content.ScriptContent; | ||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; | ||
import org.kohsuke.stapler.bind.JavaScriptMethod; | ||
|
||
/** | ||
* | ||
* @author acearl | ||
*/ | ||
public class EmailExtTemplateAction implements Action { | ||
|
||
private AbstractProject<?,?> project; | ||
|
||
public EmailExtTemplateAction(AbstractProject<?,?> project) { | ||
this.project = project; | ||
} | ||
|
||
public String getIconFileName() { | ||
return "/plugin/email-ext/images/template-debugger.png"; | ||
} | ||
|
||
public String getDisplayName() { | ||
return Messages.EmailExtTemplateAction_DisplayName(); | ||
} | ||
|
||
public String getUrlName() { | ||
return "templateTest"; | ||
} | ||
|
||
private String renderError(Exception ex) { | ||
return ""; | ||
} | ||
|
||
@JavaScriptMethod | ||
public String renderTemplate(String templateFile, String buildId) { | ||
String result; | ||
|
||
try { | ||
ScriptContent content = new ScriptContent(); | ||
content.template = templateFile; | ||
AbstractBuild<?,?> build = project.getBuild(buildId); | ||
result = content.evaluate(build, TaskListener.NULL, "SCRIPT"); | ||
} catch (Exception ex) { | ||
result = renderError(ex); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public AbstractProject<?, ?> getProject() { | ||
return project; | ||
} | ||
} |
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
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
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
44 changes: 44 additions & 0 deletions
44
src/main/resources/hudson/plugins/emailext/EmailExtTemplateAction/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,44 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" | ||
xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
<l:layout xmlns:plugin="/hudson/plugins/javancss/tags"> | ||
<script type="text/javascript"> | ||
function onSubmit() { | ||
var templateTester = <st:bind value="${it}"/> | ||
var templateFile = document.getElementById('template_file_name').value | ||
var buildId = document.getElementById('template_build').value | ||
templateTester.renderTemplate(templateFile,buildId, function(t) { | ||
document.getElementById('rendered_template').innerHTML = t.responseObject(); | ||
}); | ||
return false; | ||
} | ||
</script> | ||
<st:include it="${it.project}" page="sidepanel.jelly"/> | ||
<l:main-panel> | ||
<h1>${it.displayName}</h1> | ||
<p> | ||
${%description} | ||
</p> | ||
<form action="" method="post" name="templateTest" onSubmit="return onSubmit();"> | ||
<table> | ||
<f:entry title="${%Groovy Template File Name}"> | ||
<f:textbox name="template_file_name" id="template_file_name" clazz="required" checkUrl="'${rootURL}/plugin/email-ext/templateFileCheck?value='+this.value" /> | ||
</f:entry> | ||
<f:entry title="${%Build To Test}"> | ||
<select name="template_build" id="template_build"> | ||
<j:forEach var="build" items="${it.project.builds}"> | ||
<option value="${build.id}">#${build.number} (${build.result})</option> | ||
</j:forEach> | ||
</select> | ||
</f:entry> | ||
<f:entry> | ||
<f:submit value="${%Go}!"/> | ||
</f:entry> | ||
</table> | ||
</form> | ||
<div id="rendered_template"> | ||
|
||
</div> | ||
</l:main-panel> | ||
</l:layout> | ||
</j:jelly> |
2 changes: 2 additions & 0 deletions
2
src/main/resources/hudson/plugins/emailext/EmailExtTemplateAction/index.properties
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,2 @@ | ||
description=Enter the template file name and select a build to test with then\ | ||
press the "Go!" button to render the template based on the selected build. |
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.