Store data in Jenkins job description I have a job which I run with a boolean parameter called "BUILD_CLEAN=true", and it defaults to false. I can store this flag in the job ID currentBuild.displayName . Simple enough. But for my purposes I also want to save the commit hash(es) of that build as well, which starts becoming a silly place to store metadata. I'm probably not getting the terminology right, but here is my use case.

My Pipeline declarative job builds a repo, a subrepo and all using shell, and archives the binary artifacts. The code is of mixed types, so Artifactory is not an option for part of this solution either. I want to save just the hashes someplace, to make it easy for subsequent builds made in the same day (24 hours) to inspect/list them, and trigger a separate job with the full list for that day. Do I save these hashes/values into an XML file per build? What is the best way to make extracting small pieces of data easy? GOAL: I'm attempting to implement a kind of generalized incremental build job, but am unable to use any of the plugins since I'm building for 5 different targets, some of them across nodes. In my specially marked build (nightly) every 24 hours, I'm .bz2 zipping the objects so I can restore them for any incremental. So it's this archive that I'm wanting to find, check the hashes and retrieve into my workspace.

TAGS: Jenkins,pipeline,tags,incremental (I'm unable to define any tags due to the rep system.)
Not sure if this would work for you, but what I do is store all of the build metadata into a BuildInfo.json file. You could just save it as an XML file like you said, but I found it easier to parse info with Groovy if it was a JSON file. Along with the most recent commit hash, we store most of the build information in this file, including the result, duration, user who kicked off the build, etc.

One advantage of this approach is we're able to create other jobs that take action of already built products, such as for deployments. These jobs can just look for the presence of a BuildInfo.json file and take action based off the information contained within. Example:

import groovy.json.*

def build_info = [
    'Product': 'MyApp',
    'Build Type': 'Full',
    'Build Name': currentBuild.displayName,
    'Version': '1.2.3.4',
    'Source Branch' : params.Branch,
]

def json_output = readJSON text: groovy.json.JsonOutput.toJson(build_info)
writeJSON file: "BuildInfo.json", json: json_output, pretty: 4