My requirement is to display the findbugs total, fixed and new warnings in email using jenkins. I am using static_analysis.jelly script through email-ext plugin but I am not able to get the count. this is the code I am using:
<j:set var="fb" value="${it.getAction('hudson.plugins.findbugs.FindBugsResultAction')}" />
<table width="100%">
<tr><td colspan="2"><b>Findbugs Result</b></td></tr>
<tr><td>Total:</td><td>${fb.result.numberOfWarnings}</td></tr>
<tr><td>Fixed:</td><td>${fb.result.numberOfFixedWarnings}</td></tr>
<tr><td>New:</td><td>${fb.result.numberOfNewWarnings}</td></tr>
<tr><td colspan="2">View Report</td></tr>
</table>
I am using Jenkins version 1.5.42. All the reports are generated through mavens correctly. Any clue is highly appreciated.
Thanks,
Sanjiv
Related
I am using email ext syntax to send the email in pipeline as code and having an HTML template to send the email.
I need to access the Jenkins environment variable in HTML template. It is working for standard environment variables like BUILD_URL. But it is not working for environment variable set with env.VARIABLE='VALUE'. If I try to access ${VARIABLE} in HTML template it is not working.
Any idea please.
To get environment variables in your template, you should use some scripts to access Jenkins API.
In Jenkins there are two most popular options that I know: Groovy templates and Jelly templates.
Some more info you can find on Email-ext plugin page.
I have the same problem here: Access custom environment variables in jelly template, but I was able to get access to build parameters.
Here is a template how to do that with Jelly:
<?jelly escape-by-default='true'?>
<!DOCTYPE html [
<!ENTITY nbsp "&nbsp;">
]>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<head>
<style>
body table, td, th, p, h1, h2 {
margin:0;
font:normal normal 100% Georgia, Serif;
background-color: #ffffff;
}
</style>
</head>
<body>
<j:set var="buildEnv" value="${build.getEnvironment(listener)}" />
<j:set var="myVar" value="${buildEnv.get('MY_BUILD_PARAMETER')}" />
<table>
<tr>
<td>Variable</td>
<td>
<p>${myVar}</p>
</td>
</tr>
</table>
</div>
</body>
</j:jelly>
So, you just need add some jelly tags, and to get build parameters value in this templates you need call getEnvironment method from build object.
<j:set var="buildEnv" value="${build.getEnvironment(listener)}" />
<j:set var="myVar" value="${buildEnv.get('MY_BUILD_PARAMETER')}" />
Below text in Jenkins File worked for me
env.CURRENT_BRANCH = master
env.PIPELINE_TYPE = mytype
Below lines in Jelly\HTML file
Using the below variable all the environment variables defined in Jenkins can be accessible
${customEnvVar.PIPELINE_TYPE}-${customEnvVar.CURRENT_BRANCH}
Before this code customEnvVar needs to defined
< j:set var="customEnvVar" value="${it.getAction('org.jenkinsci.plugins.workflow.cps.EnvActionImpl').getOverriddenEnvironment()}"/>
All,
I have been trying to figure this UI piece of my jenkins plugin for a few hours now. I am trying to nest checkboxes inside a radioBlock. The problem I am having is that the checkboxes are not hidden when the page loads at first. To hide them I have to highlight the radio then deselect.
<f:section title="Deployment method">
<f:radioBlock checked="true" name="deployMethod" title="Deploy new servers" value="Deploy new Servers"/>
<f:radioBlock checked="false" name="deployMethod" title="Script Deploy" value="Script deploy">
<j:forEach var="script" items="${account.scripts}">
<f:entry>
<f:checkbox name="Scripts" value="${script.scriptName}" title="${script.scriptName}"/>
</f:entry>
</j:forEach>
</f:radioBlock>
</f:section>
You need to put all the content you want to hide inside this:
<f:radioBlock checked="false" name="deployMethod" title="Script Deploy" value="Script deploy">
<f:nested>
....
</f:nested>
</f:radioBlock>
I am trying to read set of files ending with .errors extensions and trying to make them a part of the email sent out by jenkins via email-extension plugin. I have taken the basic html.jelly and trying to modify it. I am getting what looks like syntax errors. I don't really know how to debug it. But I went back to original and added stuff in steps. I start getting the errors when I add the ant:fileScanner
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:ant="jelly:ant">
<BODY>
<j:set var="buildenv" value="${build.getEnvironment(listener)}"/>
<j:set var="parentWorkspace" value="${buildenv.get('PARENT_WORKSPACE')}"/>
<ant:fileScanner var="errorFiles">
<ant:fileset dir="${parentWorkspace}">
<ant:include name="*.errors" />
</ant:fileset>
</ant:fileScanner>
<j:forEach var="errorFile" items="$(errorFiles)">
<util:loadText file="${errorFile}" var="errorText"/>
<TR>
<TD>${errorText}</TD>
</TR>
</j:forEach>
<BR/>
</BODY>
</j:jelly>
Any help is much appreciated. I am almost at my wits end.
EDIT: Looks like any ANT task I am trying to invoke in the jelly script is leading to errors. So looks like I am doing something wrong on ANT front. I do have ANT installed on the machine if that makes a difference.
I'd like to send an email after a build completes with some data from the reports that are run (PMD, Checkstyle, Findbugs, Cobertura) such as number of issues, new issues, coverage etc.
Is this possible?
I've managed to get some data using the email-ext plugin. You need to include a jelly file in the email sent like this:
${JELLY_SCRIPT, template="html"}
There is a default template (html.jelly) which includes junit and Cobertura results which I've modified by adding something like this:
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
...
<j:set var="fb" value="${it.getAction('hudson.plugins.findbugs.FindBugsResultAction')}" />
<table width="100%">
<tr><td colspan="2"><b>Findbugs Result</b></td></tr>
<tr><td>Total:</td><td>${fb.result.numberOfWarnings}</td></tr>
<tr><td>Fixed:</td><td>${fb.result.numberOfFixedWarnings}</td></tr>
<tr><td>New:</td><td>${fb.result.numberOfNewWarnings}</td></tr>
<tr><td colspan="2">View Report</td></tr>
</table>
...
</j:jelly>
For PMD and CheckStyle you can do something similar with:
<j:set var="pmd" value="${it.getAction('hudson.plugins.pmd.PmdResultAction')}" />
<j:set var="cs" value="${it.getAction('hudson.plugins.checkstyle.CheckStyleResultAction')}" />
I've not yet found a way to include the low/medium/high priority figures for the results.
<j:set var="pmd" value="${it.getAction('hudson.plugins.pmd.PmdResultAction')}" />
<j:if test="${pmd.isEmpty()!=true}">
<TABLE width="100%">
<TR><TD colspan="2" class="bg1"><B>PMD Result</B></TD></TR>
<tr><td>Total:</td><td>${pmd.result.numberOfWarnings}</td></tr>
<tr><td>High:</td><td>${pmd.result.getNumberOfAnnotations('HIGH')}</td></tr>
<tr><td>Normal:</td><td>${pmd.result.getNumberOfAnnotations('NORMAL')}</td></tr>
<tr><td>Low:</td><td>${pmd.result.getNumberOfAnnotations('LOW')}</td></tr>
<tr><td>New:</td><td>${pmd.result.numberOfNewWarnings}</td></tr>
<tr><td>Fixed:</td><td>${pmd.result.numberOfFixedWarnings}</td></tr>
<tr><td colspan="2">View Report</td></tr>
</TABLE >
<BR/>
</j:if>
Have a try! More check my gist here: https://gist.github.com/yangboz/9204868
In my case worked https://stackoverflow.com/a/22008267/1688570
For exact Action names look in \Jenkins\jobs\fispp-all-master\builds\${buildNumber}\build.xml file.
I.e. I had to use hudson.plugins.findbugs.FindBugsMavenResultAction to show correct results.
I am using struts2 in my application and trying to diplay error message using "s:actionerror/". It diaplays fine but a dot(.) also appears with the error message which looks ugly and is displayed like list.
Is there any way to cuatomize the error message in struts2.
Thanks in advance.
Brian Yarger's answer is the most complete solution. The easiest solution on the other hand is to just use CSS and modify the li element.
JSP:
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionErrors/>
</div>
</s:if>
CSS:
li .errors { list-style: none; }
Another solution is to override the template for the default actionError output.
You can find the default templates in the struts2 core jar. If you pull out template.simple/actionerror.ftl, you can customize that. You can either come up with your own template and reference it in the s:actionerror tag with the template attribute, or you can keep the same name and put it in /template/simple and it will be used as the default.
Most of the templates are in freemarker, although there are still some of them in velocity depending on your struts2 version. Both are pretty easy to work with templating engines.
I guess the kozmic's solution should be:
JSP:
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionErrors/>
</div>
</s:if>
CSS:
div .errors li { list-style: none; }
It didn't work for me with his CSS code.
Hi I found the solution for getting rid of the dot.
<table align="center" width="70%" class="stats">
<tr>
<s:if test="hasActionErrors()">
<s:iterator value="actionErrors">
<tr>
<td class="error">
<img alt="error message" src="./images/cross.gif" width="10" height="10"/> <s:property escape="false" />
</td>
</tr>
</s:iterator>
</s:if>
Try this out.
I know this is an old question, but I want to share my simple solution. This just prints out each error message without any extra generated html markup. Then you can wrap the <s:property value="%{error}"/> in some custom html if you want.
<s:if test="hasActionErrors()">
<s:iterator var="error" value="%{actionErrors}">
<s:property value="%{error}"/>
</s:iterator>
</s:if>