Answering my own question again.  It looks like there is some API available 
for getting SCM revision info in a groovy sandbox environment. 

def getChanges() {
  def lines = []
  def changeSets = currentBuild.changeSets
  for (int i = 0; i < changeSets.size(); i++) {
    def entries = changeSets[i].items
    for (int j = 0; j < entries.length; j++) {
      def entry = entries[j]
      lines.add("${entry.commitId} by ${entry.author} on ${new 
Date(entry.timestamp)}: ${entry.msg}")
      def files = new ArrayList(entry.affectedFiles)
      for (int k = 0; k < files.size(); k++) {
        def file = files[k]
        lines.add("\t${file.editType.name} ${file.path}")
      }
    }
  }
  def string = ''
  for (i = 0; i < lines.size(); i++) {
    string += lines[i] + '\n'
  }
  return string
}

Trying to get this info from currentBuild.rawBuild seems nearly impossible 
due to sandbox / security restrictions.

On Wednesday, August 16, 2017 at 12:46:46 PM UTC-5, Dallas Clement wrote:
>
> I know that I can get the latest revision for the current build by 
> executing a shell command such as:
>       def currentCommit = sh(returnStdout: true, script: 'git rev-parse 
> HEAD').trim()
>
> But I would like to get the commit hash associated with a previous build. 
>  The reason I want to do this is so that I can list all commits associated 
> with a given build since the previous build.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/cd74bcbf-0f94-4b36-a180-4489f74bd01c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to