Fwd: How to publishHTML via Shared Library global variable steps?

508 views
Skip to first unread message

Ann B

unread,
Sep 6, 2017, 7:03:15 PM9/6/17
to jenkins...@googlegroups.com

Hi all-

 

I am attempting to perform a publishHTML post-build action in my Shared Library pipeline code.  I am having a problem coming up with the correct syntax.  


I am referencing the steps instance from my vars/runFunctionalTests.groovy global variable:

import org.magento.ci.tests.Functional
def call() {
    node {
       
def functionalTest = new Functional('Functional')
        buildImages(functionalTest)
        parallel functionalTest.execute(steps, label_slave)
    }
}

 

Snippet from Functional (src/tests/Functional.groovy) class of what I have tried but have not been successful:

@NonCPS

def execute(DSL steps, String agentLabel) {
    :    :

    // References to ArtifactArchiver and JUnitResultArchiver work fine.

    steps.step([$class: 'ArtifactArchiver', artifacts: 'results/*, *-results.tar.gz', excludes: null])
    steps.step([
$class: 'JUnitResultArchiver', allowEmptyResults: true, testResults: 'phpunit.xml'])

    // All of these attempts fail.
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'results', reportFiles: 'report.html', reportName: 'HTML Report', reportTitles: '']) 

steps.step([
$class: 'htmlpublisher.HtmlPublisherTarget', allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'results', reportFiles: 'report.html', reportName: 'ACB HTML Report', reportTitles: ''])

    def htmlReport = new htmlpublisher.HtmlPublisherTarget('ACB HTML Report', 'results', 'report.html', false, false, false)
    steps.step(htmlReport)

}

 

Thanks in advance,

 

Ann


Steffen Elste

unread,
Sep 7, 2017, 3:10:57 AM9/7/17
to Jenkins Users
Hello Ann,
we're using the publishHTML step in conjunction with Allure reports - not via a shared library but directly in a pipeline script.
Basically identical to your first attempt:

publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'target/allure-reports', reportFiles: 'index.html', reportName: 'Allure Report'])

Do You get any sort of error messages?
You might want to try and move the call to the pipeline script, if possible.
Cheers,

Steffen

Ann B

unread,
Sep 7, 2017, 11:40:22 AM9/7/17
to Jenkins Users
Hi Steffen-

publishHTML step also works fine for me from a pipeline script.  The issue is accessing it from a shared library.  From a shared library, you have to reference the DSL steps (https://support.cloudbees.com/hc/en-us/articles/217736618-How-do-I-access-Pipeline-DSLs-from-inside-a-Groovy-class-).

steps.step(publishHTML...) also does not work.

Ann

Richard Bywater

unread,
Sep 8, 2017, 4:05:45 AM9/8/17
to Jenkins Users
Are there any errors displayed or does it just ignore the line? Would be good to get a sense roughly where the issue might be originating.

Richard.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0625eb92-a198-4677-97b9-525139fa601c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ann B

unread,
Sep 8, 2017, 2:57:44 PM9/8/17
to Jenkins Users
Hi Richard-

When I try:
steps.step([$class: 'PublishHTMLStep', allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'results', reportFiles: 'report.html', reportName: 'HTML Report', reportTitles: ''])

I get this error:
syntax error near unexpected token `)'

Also tried without steps.step and got
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.magento.ci.tests.Functional.publishHTML() is applicable for argument types: (java.util.LinkedHashMap) values: [[allowMissing:false, alwaysLinkToLastBuild:false, keepAll:false, ...]]
Referencing ArtifactArchiver and JUnitResultArchiver classes works fine.

Could just be the implementation of PublishHTMLStep.  I'm just trying to figure out how to publish HMTL pages.  Perhaps there is another way.
I added a comment to this PR as it seemed related to my question - https://github.com/jenkinsci/htmlpublisher-plugin/pull/15

Thanks,

Ann

Richard Bywater

unread,
Sep 8, 2017, 11:45:59 PM9/8/17
to Jenkins Users
Hi Ann

I'm the current maintainer of the HTML Publisher plugin but unfortunately I'm not 100% up-to-speed with its use with pipeline etc. I couldn't replicate the syntax error you had so I'm wondering if that is actually being caused by a syntax error somewhere else and its reporting it incorrectly?

I have had luck following the Accessing Steps section at https://jenkins.io/doc/book/pipeline/shared-libraries/#accessing-steps - that is, I just used publishHTML inside a shared library src file so, in theory, your "publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'results', reportFiles: 'report.html', reportName: 'HTML Report', reportTitles: ''])" in the execute function *should* have worked I think as far as I can tell. If you can let me know what happens with just that there (i.e. what error/behaviour you see) then that might help track things down.

Richard.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Ann B

unread,
Sep 9, 2017, 12:30:26 AM9/9/17
to Jenkins Users
Hi Richard-

Thank you for your work with this plugin!

Yes, publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'results', reportFiles: 'report.html', reportName: 'HTML Report', reportTitles: '']) works find within the context of a shared library script in src directory.

My issue is that I've created a custom step (global variable) within the var directory of my shared library.  The way I understand it, you have to access the DSL via the steps object.  This page has more information - https://support.cloudbees.com/hc/en-us/articles/217736618-How-do-I-access-Pipeline-DSLs-from-inside-a-Groovy-class- as well as this page - https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-global-variables

If I code:

publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'results', reportFiles: 'report.html', reportName: 'HTML Report', reportTitles: '']) in my method in my class in my var directory, then I get the following error:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.magento.ci.tests.Functional.publishHTML() is applicable for argument types: (java.util.LinkedHashMap) values: [[allowMissing:false, alwaysLinkToLastBuild:false, keepAll:false, ...]]

Thanks again,

Ann

Ann B

unread,
Sep 9, 2017, 12:37:39 AM9/9/17
to Jenkins Users
Accessing steps section - https://jenkins.io/doc/book/pipeline/shared-libraries/#accessing-steps is actually a better section to look at to understand our use case.

Specifically this section:

"This approach has limitations; for example, it prevents the declaration of a superclass.

Alternately, a set of steps can be passed explicitly to a library class, in a constructor, or just one method"


I'm passing the steps instance to a method in a library class.

Richard Bywater

unread,
Sep 9, 2017, 3:49:41 AM9/9/17
to Jenkins Users
Based on the links that you provided, I've now tried the following both of which seem to work so hopefully you might be able to extract the relevant bits out and apply to your codebase (note that I'm by far any expert on pipelines - just learning them myself really!)

Attempt 1 - using a custom step
---
Pipeline
@Library('Test')
import Utilities
runFunctionalTests()

var/runFunctionalTests.groovy
def call() {
  node {
    steps.publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'target/allure-reports', reportFiles: 'index.html', reportName: 'Allure Report', reportTitles: ''])
  }
}
---

Attempt 2 - using a Groovy method
---
Pipeline
@Library('Test')
import Utilities
def utils = new Utilities(steps)
node {
    utils.doSomething()
}

src/Utilities.groovy
class Utilities implements Serializable {
  def steps
  Utilities(steps) {this.steps = steps}
  def doSomething() {
    steps.publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'target/allure-reports', reportFiles: 'index.html', reportName: 'Allure Report', reportTitles: ''])
  }
}
---

Hopefully that is of some use to you! 

Cheers
Richard.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Ann B

unread,
Sep 9, 2017, 11:38:17 AM9/9/17
to Jenkins Users
Nice!!  That was it Richard!

Sorry that did not occur to me.  I was making it way more difficult than I needed.

Thanks!

Ann

Richard Bywater

unread,
Sep 9, 2017, 5:04:18 PM9/9/17
to Jenkins Users

No worries. Glad you got it up and running. I too able sometimes guilty of making things too difficult so I know the feeling :)

Richard


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages