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 {
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.
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?