Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-43992

pipeline syntax for groovy-postbuild-plugin

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Is there a way to add a groovy postbuild step in a declarative pipeline template for creating jobs?

      The documentation at https://jenkins.io/doc/pipeline/steps/ doesn't have any references to this plugin so I assume the answer is no, but just wondered if there might be another workaround?

        Attachments

          Activity

          Hide
          tyrelh Tyrel Haveman added a comment -

          Yeah this is a bit confusing. I'd like the ability to do like manager.addShortText(textToDisplay) from a Pipeline Groovy script. It's a bit confusing because this plugin seems to be doing two things, really – its name is deceptive. It provides a way to run Groovy scripts at the end of a build, but it also provides some helpful UI widgets.

          This is how the plugin gets its manager – with the right imports you might be able to get it to work in a Pipeline script:

          TaskListener listener = new LogTaskListener(Logger.getLogger(WorkflowManager.class.getName()), Level.WARNING);
          return new GroovyPostbuildRecorder.BadgeManager(build, listener, Result.FAILURE);
          

          See WorkflowManager.java

          Show
          tyrelh Tyrel Haveman added a comment - Yeah this is a bit confusing. I'd like the ability to do like manager.addShortText(textToDisplay) from a Pipeline Groovy script. It's a bit confusing because this plugin seems to be doing two things, really – its name is deceptive. It provides a way to run Groovy scripts at the end of a build, but it also provides some helpful UI widgets. This is how the plugin gets its manager – with the right imports you might be able to get it to work in a Pipeline script: TaskListener listener = new LogTaskListener(Logger.getLogger(WorkflowManager. class. getName()), Level.WARNING); return new GroovyPostbuildRecorder.BadgeManager(build, listener, Result.FAILURE); See WorkflowManager.java
          Hide
          tyrelh Tyrel Haveman added a comment - - edited

          Actually, these might be easier to emulate in a Pipeline script:

          public void addShortText(String text) {
            build.getActions().add(GroovyPostbuildAction.createShortText(text));
          }
          
          public void addShortText(String text, String color, String background, String border, String borderColor) {
            build.getActions().add(GroovyPostbuildAction.createShortText(text, color, background, border, borderColor));
          }
          

          Those are from GroovyPostbuildRecorder.java

          The import needed is org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction

          The build is available as currentBuild.rawBuild in Pipeline Groovy scripts.

          Show
          tyrelh Tyrel Haveman added a comment - - edited Actually, these might be easier to emulate in a Pipeline script: public void addShortText( String text) { build.getActions().add(GroovyPostbuildAction.createShortText(text)); } public void addShortText( String text, String color, String background, String border, String borderColor) { build.getActions().add(GroovyPostbuildAction.createShortText(text, color, background, border, borderColor)); } Those are from GroovyPostbuildRecorder.java The import needed is org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction The build is available as currentBuild.rawBuild in Pipeline Groovy scripts.
          Hide
          joth Jonas Thyregod added a comment -

          Hi Tyrel Haveman, sadly the GroovyPostbuildAction.createShortText method is not whitelisted so it cannot be executed from the pipeline it gives a: 

          org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction createShortText 

          This method cannot be approved in the Script Approval.

          Show
          joth Jonas Thyregod added a comment - Hi Tyrel Haveman , sadly the GroovyPostbuildAction.createShortText method is not whitelisted so it cannot be executed from the pipeline it gives a:  org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction createShortText  This method cannot be approved in the Script Approval.
          Hide
          eldada Eldad Assis added a comment -

          I think this is not a minor priority task. This ability, along with the new pipeline syntax are very useful and practical.

          Show
          eldada Eldad Assis added a comment - I think this is not a minor priority task. This ability, along with the new pipeline syntax are very useful and practical.
          Hide
          alexander_samoylov Alexander Samoylov added a comment -

          Hello Jonas Thyregod,
          The workaround proposed by Tyrel Haveman worked for me. My pipeline script looks this way:

          import org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction;
          node ('myNode') {
          ...
            stage ('Post-Build') {
              currentBuild.rawBuild.getActions().add(GroovyPostbuildAction.createShortText("text"));
            }
          }
          

          Jenkins: 2.73.3
          Groovy PostBuild Plugin: 2.3.1

          The content of the approved methods ("Signatures already approved:"):

          method hudson.model.Actionable getActions
          method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
          staticMethod org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction createShortText
          java.lang.String
          
          Show
          alexander_samoylov Alexander Samoylov added a comment - Hello Jonas Thyregod , The workaround proposed by Tyrel Haveman worked for me. My pipeline script looks this way: import org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction; node ( 'myNode' ) { ... stage ( 'Post-Build' ) { currentBuild.rawBuild.getActions().add(GroovyPostbuildAction.createShortText( "text" )); } } Jenkins: 2.73.3 Groovy PostBuild Plugin: 2.3.1 The content of the approved methods ("Signatures already approved:"): method hudson.model.Actionable getActions method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild staticMethod org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction createShortText java.lang. String
          Hide
          ikedam ikedam added a comment -

          Badge and summary features are extracted to badge-plugin: https://github.com/jenkinsci/badge-plugin/blob/master/README.md
          You can use those features also in pipelines. Please try that.

          Show
          ikedam ikedam added a comment - Badge and summary features are extracted to badge-plugin: https://github.com/jenkinsci/badge-plugin/blob/master/README.md You can use those features also in pipelines. Please try that.

            People

            Assignee:
            equick Edward Quick
            Reporter:
            equick Edward Quick
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: