jenkinsci / badge-plugin

Jenkins Badge plugin
https://plugins.jenkins.io/badge/
MIT License
32 stars 43 forks source link

createSummary on another build #52

Closed elibroftw closed 4 months ago

elibroftw commented 2 years ago

Is your feature request related to a problem? Please describe.

I want to add custom summaries on another build (type WorkflowRun)

Describe the solution you'd like

workflowrun.createSummary()

or

addSummary(workflowrun, ...)

Describe alternatives you've considered

The alternative is a hack but Jenkins will auto resume any aborted builds where the hack was used to add a summary.

Additional context

I need to abort another build and then add a summary to it all without Jenkins resuming the job upon a restart.

strangelookingnerd commented 4 months ago

@elibroftw I know it has been a long time and you probably have moved on from this request. But for what its worth, here is a way to do what you are asking for in your pipeline:

// build a new action and append text to it
def action = new com.jenkinsci.plugins.badge.action.BadgeSummaryAction('info.gif');
action.appendText('Test Text');

// select the build you want - in this case it's the previous build
def build = currentBuild.getPreviousBuild().getRawBuild();

// add the action
build.addAction(action);

// persist the change
build.save();

This will require some script-approvals - in my case including RunWrapper#getRawBuild that according to script-security may introduce a security vulnerability.