Retrieve parameterized triggered build display name with groovy script

Using the groovy plugin and Jenkins Parameterized Trigger plugin, we can create a groovy script that retrieves the previous triggered build number from the environment variables set by the Parameterized Trigger plugin, then use the groovy plugin to lookup the displayName for the build (assuming the display name is different using Build Name Setter Plugin).

The display name in my case will be the git hash/revision that was built in the previous step.

import hudson.model.*
  def previous_build_number = build.getEnvironment(listener).get("TRIGGERED_BUILD_NUMBER_Build_byGitHash")
  def previous_git_hash = jenkins.model.Jenkins.instance.getItem("Build-byGitHash").getBuildByNumber(previous_build_number.toInteger()).displayName

def pa = new ParametersAction([
  new StringParameterValue("PREVIOUS_GIT_HASH", previous_git_hash)

// add variable to current job