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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Ann B

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


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAD4O2JnprWcD5ZP_bvfsyNNZSovbRQ6e2vSgF9Ri%3DbF4mdYm1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Steffen Elste
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/82795cb8-c33f-43b8-bbba-2c66a030e497%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Ann B
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

On Thursday, September 7, 2017 at 12:10:57 AM UTC-7, Steffen Elste wrote:
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

--
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

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

Richard Bywater-2
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.

On Fri, 8 Sep 2017 at 03:40 Ann B <[hidden email]> wrote:
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


On Thursday, September 7, 2017 at 12:10:57 AM UTC-7, Steffen Elste wrote:
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

--
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 [hidden email].
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAMui946hbKiWCG3yiD%3DAUXYd7_QVfa0xYZJMCeKZum_Wo0h%2BGQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Ann B
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a843956e-e4df-45e0-9a4e-59343c539a25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Richard Bywater-2
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.

On Sat, 9 Sep 2017 at 06:57 Ann B <[hidden email]> wrote:
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a843956e-e4df-45e0-9a4e-59343c539a25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAMui945A1UXUXMVcyis1r-%3DpWM__KswORCHYmSfJdsnZat7UaA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Ann B
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3a5e2623-a429-4d9e-9f3f-3e3be0b10bb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Ann B
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.

On Friday, September 8, 2017 at 9:30:26 PM UTC-7, Ann B wrote:
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 - <a href="https://support.cloudbees.com/hc/en-us/articles/217736618-How-do-I-access-Pipeline-DSLs-from-inside-a-Groovy-class-" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsupport.cloudbees.com%2Fhc%2Fen-us%2Farticles%2F217736618-How-do-I-access-Pipeline-DSLs-from-inside-a-Groovy-class-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFV2eQcyZpEB_IRz94A3o80I_sjqQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsupport.cloudbees.com%2Fhc%2Fen-us%2Farticles%2F217736618-How-do-I-access-Pipeline-DSLs-from-inside-a-Groovy-class-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFV2eQcyZpEB_IRz94A3o80I_sjqQ&#39;;return true;">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 - <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-global-variables" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fbook%2Fpipeline%2Fshared-libraries%2F%23defining-global-variables\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFM978Wq5w9uFcmAKL_0Tv9nSIaOA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fbook%2Fpipeline%2Fshared-libraries%2F%23defining-global-variables\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFM978Wq5w9uFcmAKL_0Tv9nSIaOA&#39;;return true;">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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/261699f8-b0c8-4926-8de7-5db65461df55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Richard Bywater-2
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.

On Sat, 9 Sep 2017 at 16:37 Ann B <[hidden email]> wrote:
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.


On Friday, September 8, 2017 at 9:30:26 PM UTC-7, Ann B wrote:
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/261699f8-b0c8-4926-8de7-5db65461df55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAMui946XBQ8iE%3DEKhWL%3DMsZ4TthZ0ocPYMT-Rp2-UtwttZJgvQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Ann B
Nice!!  That was it Richard!

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

Thanks!

Ann

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bc2113f3-79ab-4370-ab30-992f7fbc2878%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Richard Bywater-2

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


On Sun, 10 Sep 2017, 3:38 AM Ann B <[hidden email]> wrote:
Nice!!  That was it Richard!

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

Thanks!

Ann

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bc2113f3-79ab-4370-ab30-992f7fbc2878%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAMui947ifDCEKGBRPCZuS6ZOCDun1HuUz4mGiBhM-wH-PU9-sg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.