Add Publisher Maven artifacts to mail template

138 weergaven
Naar het eerste ongelezen bericht

Harsh Shah

ongelezen,
18 apr 2019, 20:15:1118-04-2019
aan 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

ongelezen,
19 apr 2019, 12:30:4919-04-2019
aan 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

ongelezen,
19 apr 2019, 13:06:0119-04-2019
aan 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

ongelezen,
21 apr 2019, 12:15:5021-04-2019
aan 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

ongelezen,
22 apr 2019, 02:48:0322-04-2019
aan Jenkins Users
Hi,
  Thanks, this works.

-Harsh

Harsh Shah

ongelezen,
22 apr 2019, 02:49:1422-04-2019
aan 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

ongelezen,
22 apr 2019, 06:22:3422-04-2019
aan 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

ongelezen,
26 apr 2019, 19:59:5326-04-2019
aan 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

ongelezen,
30 mei 2019, 17:51:1330-05-2019
aan Jenkins Users

RicardF

ongelezen,
13 feb 2020, 09:09:0113-02-2020
aan 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

ongelezen,
13 feb 2020, 09:45:4913-02-2020
aan 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...
Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten