- 2014.10.14, 16:18
- here's a recipe how to publish Fingerprints from Jenkins BuildFlow plugin (Groovy):
I donate this code to PUBLIC DOMAIN:
def fingerprint_name = "hudsonBuild.properties"
def buildStartNumber = upstream.number
out.println "* this build triggered by: $buildStartNumber"
/** copy file from given (upstream) build workspace, returning the copied File (needed for calling Fingerprinter) */
def copy_to_current_workspace( file_name, from_workspace )
{
def upstream_fingerprint = new File( from_workspace + "/" + file_name )
out.println "Copying fingerprint file from upstream $upstream_fingerprint"
def current_workspace = build.environment["WORKSPACE"]
def current_workspace_fingerprint = new File( current_workspace + "/" + file_name )
out.println " . copy to $current_workspace_fingerprint"
def ant_builder = new AntBuilder()
ant_builder.copy( file: upstream_fingerprint, tofile: current_workspace_fingerprint )
return current_workspace_fingerprint
}
/** register the fingerprint File with Jenkins tracking, returning md5sum (needed to providing FingerprintAction Facet to build) */
def register_fingerprint_entry( workspace_file )
{
def md5sum = new hudson.FilePath( workspace_file ).digest()
def finger_map = jenkins.model.Jenkins.getInstance().getFingerprintMap()
def fingerprint_entry = finger_map.getOrCreate( null, workspace_file.name, md5sum ) // do not claim to originate the fingerprint
fingerprint_entry.addFor( build ) // actually registers the fingerprint with this build
return md5sum
}
/** ask jenkins to show 'See Fingerprints' link on build */
def register_action_facet( fingerprint_name, md5sum )
{
// record the fact that build has fingerprints section/facet by adding FingerprintAction display link to build
def record = [:]
record.put( fingerprint_name, md5sum )
out.println " . record: $record"
def fingerprinter = build.getAction( hudson.tasks.Fingerprinter.FingerprintAction.class )
if( fingerprinter != null ) {
fingerprinter.add( record )
out.println " . used existing fingerinter action"
} else {
build.addAction( new hudson.tasks.Fingerprinter.FingerprintAction( build, record ) )
out.println " . added fingerprinter action"
}
}
/** do it */
def register_fingerprint( workspace_file )
{
def md5sum = register_fingerprint_entry( workspace_file )
register_action_facet( workspace_file.name, md5sum )
}
def workspace_fingerprint = copy_to_current_workspace( fingerprint_name, upstream.environment["WORKSPACE"] )
register_fingerprint( workspace_fingerprint )
-
0 rakstair doma