Skip to content

Instantly share code, notes, and snippets.

@dnozay
Last active June 27, 2019 17:16
Show Gist options
  • Save dnozay/fc528b43cf27755017cc to your computer and use it in GitHub Desktop.
Save dnozay/fc528b43cf27755017cc to your computer and use it in GitHub Desktop.
Jenkins - add badge & summary to promoted build
// When using the Promoted Build plugin, you may want to perform some operations
// then you may also want to add badges or a summary to the target build as
// opposed to the promotion build. This script assumes that you have a manual
// promotion process with a parameter called RELEASE_VERSION (hence requiring
// user input); the content that follows would be what you put as a Groovy
// Postbuild action on the promotion process.
import org.jvnet.hudson.plugins.groovypostbuild.*;
def add_release_version(promotion) {
target = promotion.target;
// access the promotion build environment and the RELEASE_VERSION parameter.
release_version = promotion.environment.get('RELEASE_VERSION');
// create the summary with the gold star icon and attach to target.
GroovyPostbuildSummaryAction action = new GroovyPostbuildSummaryAction("star-gold.png");
target.getActions().add(action);
// customize text for the summary.
action.appendText("RELEASE VERSION = " + release_version, false);
// also add a short text that will appear in the build history
target.getActions().add(GroovyPostbuildAction.createShortText(release_version));
// save the build!
target.save()
}
// get the build that this promotion is for.
promotion = manager.build;
add_release_version(promotion);
@lvthillo
Copy link

import org.jvnet.hudson.plugins.groovypostbuild.*; fails for me?

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 82: unable to resolve class GroovyPostbuildSummaryAction 
 @ line 82, column 34.
       GroovyPostbuildSummaryAction action = new GroovyPostbuildSummaryAction("star-gold.png");
                                    ^

WorkflowScript: 82: unable to resolve class GroovyPostbuildSummaryAction 
 @ line 82, column 43.
   stbuildSummaryAction action = new Groovy

@dnozay
Copy link
Author

dnozay commented Jun 27, 2019

@lvthillo - you may need to install the relevant plugin for the classes to be available.

@dnozay
Copy link
Author

dnozay commented Jun 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment