Would you be willing to add this information to the "Writing Pipeline Compatible Plugins <https://jenkins.io/doc/developer/plugin-development/pipeline-integration/>" page on jenkins.io? It seems like a very useful addition to the documentation on that page.
On Wed, May 15, 2019 at 12:01 PM Devin Nusbaum <[email protected]> wrote: > Pipeline: API 2.34 added a new API called WarningAction > <https://github.com/jenkinsci/workflow-api-plugin/blob/c84dbab8cd35c90f70d84390dc711901fa73b7ad/src/main/java/org/jenkinsci/plugins/workflow/actions/WarningAction.java> > that > allows steps to report irregular but non-fatal events that occurred during > their execution while allowing Pipeline execution to continue normally. > This allows long-standing and highly-voted issues such as JENKINS-39203 > <https://issues.jenkins-ci.org/browse/JENKINS-39203> to be fixed by > modifying Pipeline steps that change the build result directly to also use > the new API so that visualizations such as Blue Ocean use the new API > (through Pipeline: Graph Analysis 1.10) to display more specific statuses. > For any maintainers of plugins setting the build result directly today, > here is some information to help you understand how to use the new API if > you would like to do so. > > First, if you have a step that throws an exception today to indicate > failure, that's totally fine, keep doing that! The new API only applies to > steps that want to indicate some kind of problem but continue normal > Pipeline execution. > > For regular Steps, if you have code in a StepExecution that does something > like this and want to use the new API: > > getContext().get(Run.class).setResult(...); > > Keep setting the build result the same way and add code to add a > WarningAction to the current FlowNode like this: > > getContext().get(Run.class).setResult(...); > getContext().get(FlowNode.class).addOrReplaceAction(new > WarningAction(...).withMessage(...)); > > The result you pass to the WarningAction constructor will determine how > Blue Ocean displays your step and the stage or parallel branch enclosing > your step. The message is optional and may be visualized directly in Blue > Ocean in some prominent way in the future, but for now it is not shown > anywhere. > > See this pull request <https://github.com/jenkinsci/junit-plugin/pull/118> > to JUnit plugin for an example of how to integrate a plugin with the new > API (in particular the changes to JUnitResultsStepExecution.java). > > If your plugin currently uses SimpleBuildStep or SimpleBuildWrapper to > implement a step that can be used in Freestyle and Pipeline jobs, there is > no way to use the new API directly, and you need to create a new Pipeline > Step to be able to use the new API. You should be able to call the > SimpleBuildStep from your new Step to avoid duplicating logic, but > unfortunately you will need to duplicate getters and setters to make > data-binding work correctly for the step. Here is an in-progress PR > <https://github.com/jenkinsci/warnings-ng-plugin/pull/58> to Warnings > Next Generation Plugin that shows what this kind of change might look like. > > See UnstableStep.java > <https://github.com/jenkinsci/workflow-basic-steps-plugin/blob/06075283ed70063937a7175da4852f9ddb087130/src/main/java/org/jenkinsci/plugins/workflow/steps/UnstableStep.java> > for an example of a new step that uses the new API. > > Thanks, and let me know if you have any questions! > > Devin > > -- > You received this message because you are subscribed to the Google Groups > "Jenkins Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jenkinsci-dev/4cd76eee-f788-40b2-98a1-51c1172113ec%40googlegroups.com > <https://groups.google.com/d/msgid/jenkinsci-dev/4cd76eee-f788-40b2-98a1-51c1172113ec%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Thanks! Mark Waite -- You received this message because you are subscribed to the Google Groups "Jenkins Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAO49JtEy77cQXeXXCiqVTO_zcbszp3iS40zLMDEMq%2BmtFCFZcg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
