Getting syntax errors: JellyException: Could not parse Jelly script : null - ant

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.

Related

Jenkins pipeline as code email ext

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 "&#38;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()}"/>

Jenkins and Findbugs

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

<c:catch> does not work with <fmt:parseNumber> JSTL 1.2

I'm implementing a simple JSP page using JSTL 1.2 (Apache Taglibs). The page does the following:
<c:catch var="error">
<fmt:parseNumber var="parsedNum" value="${param.num}" />
</c:catch>
The HTML input element looks like this:
<input type="text" name="num" size="3"/>
I'm aware that the input "12a" is permitted due to the way the parsing mechanism works. Nevertheless, I would like to catch completely wrong input, e.g., "aaa". Unfortunately, the thrown exception is not managed by <c:catch>, resulting in Tomcat 7 showing the whole stack trace.
Any advice? Thanks.
Please post a testable page for us. For example, the following page works fine for me.
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:catch var="error">
<fmt:parseNumber var="parsedNum" value="aaa" />
</c:catch>
${parsedNum}
${error}

Migration from JSF1.2+Facelets TO JSF2, "component with duplicate id" issue

I am migrating application from JSF1.2/MyFaces+Facelets TO JSF2.1/MyFaces. I have following template which used to work with JSF1.2/MyFaces+Facelets.
<ui:component>
<f:subview id="#{id}">
.
.
<script
function blockLinkClicks(){
//Disables all the HyperLink Controls to prevent repeated submits
var allLinks = document.getElementById("#{id}:treeNodeForm").getElementsByTagName('a');
var count = allLinks.length;
.
.
</script>
.
.
.
<h:form id="treeNodeForm">
<h:panelGroup id="treePanelId">
<t:tree2 id="tree2Id"
value="#{treeBean.treeModel}" var="node" varNodeToggler="t"
binding="#{treeBean.component}" clientSideToggle="false" showNav="false">
<f:facet name="selectableNode">
<h:panelGrid id="tree2PGridSelNodeId" columns="3" cellpadding="0" cellspacing="0" border="0">
.
.
.
After migration, I am getting the following error:
java.lang.IllegalStateException: component with duplicate id "mainLeftTree:treeNodeForm:tree2Id:tree2PGridSelNodeId" found
at org.apache.myfaces.view.facelets.compiler.CheckDuplicateIdFaceletUtils.checkIds(CheckDuplicateIdFaceletUtils.java:100)
at org.apache.myfaces.view.facelets.compiler.CheckDuplicateIdFaceletUtils.checkIds(CheckDuplicateIdFaceletUtils.java:116)
I have found similar questions here in SO but I was not able to relate the solutions, with my above issue. I have tried to find solution for many days/hours but could not.
Please help with your advice and pointers that I can try for a fix, as I am not sure if the issue is with f:subview or t:tree2 or jsf2 facelets.
Thank you very much in advance.
Regards,
Kumar.
I think the problem is caused by the use of <f:subview id="#{id}>", which obviously will break when PSS is enabled, because the EL is evaluated each time the view is built. Try first setting the web config parameter javax.faces.PARTIAL_STATE_SAVING to false. Or you can use the config parameter javax.faces.FULL_STATE_SAVING_VIEW_IDS to indicate which views needs full state saving. Maybe it is a good idea to avoid the EL in the id, and use other strategy in that part, but that could require some changes in the logic.

Can I configure jenkins to send an email with a static analysis report summary?

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.

Resources