The groovy post build action is currently not available in a Jenkins Workflow. In order to be compatible, the plug in must implement SimpleBuildStep.
      see https://github.com/jenkinsci/workflow-plugin/blob/master/basic-steps/CORE-STEPS.md#adding-support-from-plugins for details

      Also see
      https://github.com/jenkinsci/workflow-plugin/blob/master/COMPATIBILITY.md

          [JENKINS-26918] Workflow support for Groovy Postbuild

          Roland Schulz added a comment -

          Anyone working on this atm? I would be interested in doing it. But I have difficulty getting started. Is there anywhere a tutorial of how to make a such a plugin for workflow? Any other helpful tips to get started with this?

          Roland Schulz added a comment - Anyone working on this atm? I would be interested in doing it. But I have difficulty getting started. Is there anywhere a tutorial of how to make a such a plugin for workflow? Any other helpful tips to get started with this?

          Jesse Glick added a comment -

          See the guide for general tips, but this plugin is probably more of a special case. (Turning GroovyPostbuildRecorder into a SimpleBuildStep would not work well.)

          It is not obvious to me what aspects of the plugin are useful to support from Workflow. You can already run Groovy code of your choice, and update the build description:

          currentBuild.description = "This was building ${someComputedValue}!"
          

          So we need to clearly determine which features are unique to this plugin—previously mentioned were badges and summary actions—and decide on a reasonably intuitive way of exposing those to Workflow scripts.

          The simplest approach would be to update BadgeManager to support Run rather than only AbstractBuild, then expose it using the GlobalVariable extension point as manager. Then from Workflow you could use essentially the same syntax as in a post-build script from a freestyle project:

          manager.addWarningBadge 'Lots of tests skipped, watch out!'
          

          There is a catch: to find the build associated with the CpsScript would seem to require an API change, as seen by this use of package access. I actually introduced such an API in an aborted attempt to solve JENKINS-30222:

          diff --git a/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java b/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java
          index 69a24c9..23501bf 100644
          --- a/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java
          +++ b/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java
          @@ -136,6 +140,10 @@ public abstract class CpsScript extends SerializableScript {
                   }
               }
           
          +    public CpsFlowExecution $execution() {
          +        return execution;
          +    }
          +
               @Override
               public Object evaluate(String script) throws CompilationFailedException {
                   // this might throw the magic CpsCallableInvocation to execute the script asynchronously
          

          A more integrated approach would be to create an extension point so that RunWrapper (used for currentBuild in core Workflow) could be given additional methods and properties by plugins, so that you could write

          currentBuild.addWarningBadge 'Lots of tests skipped, watch out!'
          

          but this would be more work and require more knowledge of Groovy intricacies.

          Jesse Glick added a comment - See the guide for general tips, but this plugin is probably more of a special case. (Turning GroovyPostbuildRecorder into a SimpleBuildStep would not work well.) It is not obvious to me what aspects of the plugin are useful to support from Workflow. You can already run Groovy code of your choice, and update the build description: currentBuild.description = "This was building ${someComputedValue}!" So we need to clearly determine which features are unique to this plugin—previously mentioned were badges and summary actions—and decide on a reasonably intuitive way of exposing those to Workflow scripts. The simplest approach would be to update BadgeManager to support Run rather than only AbstractBuild , then expose it using the GlobalVariable extension point as manager . Then from Workflow you could use essentially the same syntax as in a post-build script from a freestyle project: manager.addWarningBadge 'Lots of tests skipped, watch out!' There is a catch: to find the build associated with the CpsScript would seem to require an API change, as seen by this use of package access . I actually introduced such an API in an aborted attempt to solve JENKINS-30222 : diff --git a/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java b/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java index 69a24c9..23501bf 100644 --- a/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java +++ b/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java @@ -136,6 +140,10 @@ public abstract class CpsScript extends SerializableScript { } } + public CpsFlowExecution $execution() { + return execution; + } + @Override public Object evaluate( String script) throws CompilationFailedException { // this might throw the magic CpsCallableInvocation to execute the script asynchronously A more integrated approach would be to create an extension point so that RunWrapper (used for currentBuild in core Workflow) could be given additional methods and properties by plugins, so that you could write currentBuild.addWarningBadge 'Lots of tests skipped, watch out!' but this would be more work and require more knowledge of Groovy intricacies.

          Daniel Beck added a comment -

          The "native" ability to add badges and actions of some kind to the workflow build itself would be a valuable improvement to workflow (job plugin) itself IMO.

          Daniel Beck added a comment - The "native" ability to add badges and actions of some kind to the workflow build itself would be a valuable improvement to workflow (job plugin) itself IMO.

          Jesse Glick added a comment -

          to find the build associated with the CpsScript would seem to require an API change

          I am making another pass at JENKINS-30222 which would involve making $build public in WF 1.11, removing that blocker.

          Jesse Glick added a comment - to find the build associated with the CpsScript would seem to require an API change I am making another pass at JENKINS-30222 which would involve making $build public in WF 1.11, removing that blocker.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          pom.xml
          src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java
          src/main/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowManager.java
          src/main/resources/org/jvnet/hudson/plugins/groovypostbuild/WorkflowManager/help.jelly
          src/test/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowTest.java
          http://jenkins-ci.org/commit/groovy-postbuild-plugin/0fa6ec9c1f547892e2a15be131c600949d875399
          Log:
          [FIXED JENKINS-26918] Binding BadgeManager to a global variable for Workflows.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java src/main/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowManager.java src/main/resources/org/jvnet/hudson/plugins/groovypostbuild/WorkflowManager/help.jelly src/test/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowTest.java http://jenkins-ci.org/commit/groovy-postbuild-plugin/0fa6ec9c1f547892e2a15be131c600949d875399 Log: [FIXED JENKINS-26918] Binding BadgeManager to a global variable for Workflows.

          Code changed in jenkins
          User: ikedam
          Path:
          pom.xml
          src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java
          src/main/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowManager.java
          src/main/resources/org/jvnet/hudson/plugins/groovypostbuild/WorkflowManager/help.jelly
          src/test/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowTest.java
          http://jenkins-ci.org/commit/groovy-postbuild-plugin/fd4558976706395cd6752720277a90eef92a7be9
          Log:
          Merge pull request #24 from jglick/workflow-JENKINS-26918

          JENKINS-26918 Workflow support

          Compare: https://github.com/jenkinsci/groovy-postbuild-plugin/compare/a12047227760...fd4558976706

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: pom.xml src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java src/main/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowManager.java src/main/resources/org/jvnet/hudson/plugins/groovypostbuild/WorkflowManager/help.jelly src/test/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowTest.java http://jenkins-ci.org/commit/groovy-postbuild-plugin/fd4558976706395cd6752720277a90eef92a7be9 Log: Merge pull request #24 from jglick/workflow- JENKINS-26918 JENKINS-26918 Workflow support Compare: https://github.com/jenkinsci/groovy-postbuild-plugin/compare/a12047227760...fd4558976706

          ikedam added a comment -

          Released groovy-postbuild 2.3.
          You can use manager in workflow scripts.

          ikedam added a comment - Released groovy-postbuild 2.3. You can use manager in workflow scripts.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          COMPATIBILITY.md
          http://jenkins-ci.org/commit/workflow-plugin/c4519c3f20066219c2a67c085a4a22eea27d4420
          Log:
          JENKINS-26918 Noting.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: COMPATIBILITY.md http://jenkins-ci.org/commit/workflow-plugin/c4519c3f20066219c2a67c085a4a22eea27d4420 Log: JENKINS-26918 Noting.

          Hi,

          I understand that Groovy Postbuild is now compatible with pipeline, however I can't find how to add it to my pipeline code. I expected to find a postbuild command in pipeline snippet generator, but it is not there (or at least I cannot find it).

          We have Jenkins Enterprise 2.7.21, Groovy Postbuild 2.3.1.

          Will appreciate any help with this.

           

          Igor Litmanovich added a comment - Hi, I understand that Groovy Postbuild is now compatible with pipeline, however I can't find how to add it to my pipeline code. I expected to find a postbuild command in pipeline snippet generator, but it is not there (or at least I cannot find it). We have Jenkins Enterprise 2.7.21, Groovy Postbuild 2.3.1. Will appreciate any help with this.  

          Jesse Glick added a comment -

          Look under Global Variables IIRC.

          Jesse Glick added a comment - Look under Global Variables IIRC.

            jglick Jesse Glick
            gordin Christoph Vogtländer
            Votes:
            3 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: