Add Publisher Maven artifacts to mail template

137 views
Skip to first unread message

Harsh Shah

unread,
Apr 18, 2019, 8:15:11 PM4/18/19
to Jenkins Users
Hi,
  We have been using pipeline maven plugin and maven artifact publisher to display deployed artifacts by the build. 

  We also use ext-email plugin with a template to provide notifications. 

How can I get the published maven artifacts from maven artifact publisher in my email description?

 
Thanks,
-Harsh

Cyrille Le Clerc

unread,
Apr 19, 2019, 12:30:49 PM4/19/19
to Jenkins Users
do you have examples of integrations of the email ext plugin with other plugins?
Is the integration based on environment variables?

Cyrille

Harsh Shah

unread,
Apr 19, 2019, 1:06:01 PM4/19/19
to Jenkins Users
The template is a pretty standard template like this https://wiki.jenkins.io/download/attachments/3604514/jenkins-matrix-email-html.template?version=1&modificationDate=1332562186000&api=v2
I am trying to get maven artifacts urls

    <!-- MAVEN ARTIFACTS -->
    <j:set var="mbuilds" value="${build.moduleBuilds}" />
    <j:if test="${mbuilds!=null}">
      <div class="content">
        <h1>Build Artifacts</h1>
        <j:forEach var="m" items="${mbuilds}">
          <h2>${m.key.displayName}</h2>
          <j:forEach var="mvnbld" items="${m.value}">
            <j:set var="artifacts" value="${mvnbld.artifacts}" />
            <j:if test="${artifacts!=null and artifacts.size()&gt;0}">
              <ul>
                <j:forEach var="f" items="${artifacts}">
                  <li>
                    <a href="${rooturl}${mvnbld.url}artifact/${f}">${f}</a>
                  </li>
                </j:forEach>
              </ul>
            </j:if>
          </j:forEach>
        </j:forEach>
        <br />
      </div>
    </j:if>

Cyrille Le Clerc

unread,
Apr 21, 2019, 12:15:50 PM4/21/19
to Jenkins Users
Hello Harsh,


This seems to be possible but I have not tried. It should look like:

Collection<org.jenkinsci.plugins.pipeline.maven.MavenArtifact> generatedArtifacts = build.getAction(org.jenkinsci.plugins.pipeline.maven.publishers.MavenReport.class).getGeneratedArtifacts();

for (MavenArtifact generatedArtifact:generatedArtifacts) {
    if (generatedArtifact.isDeployed()) {
        System.out.println("<a href='" + generatedArtifact.getUrl() + "'>" + generatedArtifact.getShortDescription() + "</a>");
    } else {
        System.out.println(generatedArtifact.getShortDescription());
    }
}



Cyrille

Harsh Shah

unread,
Apr 22, 2019, 2:48:03 AM4/22/19
to Jenkins Users
Hi,
  Thanks, this works.

-Harsh

Harsh Shah

unread,
Apr 22, 2019, 2:49:14 AM4/22/19
to Jenkins Users
Collection<org.jenkinsci.plugins.pipeline.maven.MavenArtifact> generatedArtifacts = currentBuild.rawBuild.getAction(org.jenkinsci.plugins.pipeline.maven.publishers.MavenReport.class).getGeneratedArtifacts();
                    for (org.jenkinsci.plugins.pipeline.maven.MavenArtifact generatedArtifact:generatedArtifacts) {
                        if (generatedArtifact.isDeployed()) {
                            println("<a href='" + generatedArtifact.getUrl() + "'>" + generatedArtifact.getShortDescription() + "</a>");
                        } else {
                            println(generatedArtifact.getShortDescription());

Cyrille Le Clerc

unread,
Apr 22, 2019, 6:22:34 AM4/22/19
to jenkins...@googlegroups.com
Thanks Harsh,

Could you please share with us an example of using maven pipeline details in email generated by the email ext plug-in that I would add to the documentation?

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/sPAYLh1W1cM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f4ea394b-824e-4ba7-8664-46b205bb523d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harsh Shah

unread,
Apr 26, 2019, 7:59:53 PM4/26/19
to Jenkins Users
Hi, Cyrille

  So this is how I do it.


pipeline side invoke the method
 
env.DEPLOYEDARTIFACTS = getDeployedArtifacts()

@NonCPS
def getDeployedArtifacts() {
    def deployed = ''
    Collection<org.jenkinsci.plugins.pipeline.maven.MavenArtifact> generatedArtifacts = currentBuild.rawBuild.getAction(org.jenkinsci.plugins.pipeline.maven.publishers.MavenReport.class).getGeneratedArtifacts();
    for (org.jenkinsci.plugins.pipeline.maven.MavenArtifact generatedArtifact:generatedArtifacts) {
    if (generatedArtifact.isDeployed()) {
       
        deployed= deployed.concat(generatedArtifact.getUrl())
        deployed = deployed.concat("===")
        deployed = deployed.concat(generatedArtifact.getShortDescription())
        deployed = deployed.concat(",") 
        }

    }
    return deployed
}



In EXT-MAIL-STANDARD-TEMPLATE 

    <br />
    <!-- MAVEN ARTIFACTS -->
    <j:set var="mbuilds" value="${it.getAction('org.jenkinsci.plugins.workflow.cps.EnvActionImpl').getOverriddenEnvironment()}" />
        <h5>Deployed Artifacts</h5>
         <j:set var="generatedArtifacts" value="${mbuilds.get('DEPLOYEDArtifacts')}" />

       <table width="100%" style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
        <j:forEach var="artifacts" items="${generatedArtifacts.split(',')}" >
        <j:set var="artifact" value="${artifacts.split('===')}" />
         <tr bgcolor="white" >
          <td class="bg1" colspan="2" style="font-family: Verdana, Helvetica, sans serif; font-size: 120%; color: black">
          <li>
            <a href="${artifact[0]}">
            ${artifact[1]}
          </a>
          </li>
           </td>
         </tr>
         </j:forEach>
       </table>
 <br />



 
To unsubscribe from this group and all its topics, send an email to jenkins...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to jenkins...@googlegroups.com.

Cyrille Le Clerc

unread,
May 30, 2019, 5:51:13 PM5/30/19
to Jenkins Users

RicardF

unread,
Feb 13, 2020, 9:09:01 AM2/13/20
to Jenkins Users
I'm getting a null object when trying to get the deployed artifacts on command:

currentBuild.rawBuild.getAction(org.jenkinsci.plugins.pipeline.maven.publishers.MavenReport.class)

do you know what am i doing wrong?

RicardF

unread,
Feb 13, 2020, 9:45:49 AM2/13/20
to Jenkins Users
I finally got it working (should execute it after withMaven {}.

My problem is that it shows 3 of four artifacts deployed. (jar, sources, javadoc). Pom is missing, but it gets archived into the build...
Reply all
Reply to author
Forward
0 new messages