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?

          [JENKINS-43992] pipeline syntax for groovy-postbuild-plugin

          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

          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

          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.

          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.

          Hi tyrelh, 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.

          Jonas Thyregod added a comment - Hi tyrelh , 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.

          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.

          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.

          Hello joth,
          The workaround proposed by tyrelh 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
          

          Alexander Samoylov added a comment - Hello joth , The workaround proposed by tyrelh 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

          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.

          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.

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

              Created:
              Updated:
              Resolved: