Get git commit sha from other Jobs

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Get git commit sha from other Jobs

Raul Ferriz

I have two jobs: Job1 and Job2 (both are pipelines written as Jenkinfile).

Job1 is responsible for testing and building documentation.
Job2 is responsible for deploying.

Job1 can be run multiple times on the same branch and be run on other branches, may be even on distinct commit sha.

When I launch Job2, I need to setup an input list field populated with the builds of Job1.

For example:

Job1 builds:
build: 100   branch: branch1    commit sha: 1234567
build: 101   branch: branch2    commit sha: abcdefg
build: 102   branch: branch1    commit sha: a1b2c3d
build: 103   branch: branch3    commit sha: e1d1d1d

I need to build an input list with:
100 - branch1
101 - branch2
102 - branch1
103 - branch3

And when I select "102 - branch1" I need to be able to get the stored "a1b2c3d" so I can release exactly this version.

I have built the Job1 without any problem, but I'm having lots of problems building Job2.

1) I don't know how can I get  the exact commit where a external build has been run (and I cannot find anywhere on the web how to achieve it)

I'm playing with this code on Groovy console, but I could not find where the commit is stored:

import hudson.matrix.*
import jenkins.model.*;
import com.cloudbees.hudson.plugins.folder.*
import jenkins.branch.*

String propName = 'name'
def filtered = ['class', 'active']

def getPropertiesFrom(obj) {
  try { { != 'class' && != 'metaClass' }.inject([:]) { acc, e -> acc[] = e.getProperty(obj); acc }
  } catch(err) {
    return 'ERROR'

Jenkins.getInstance().getAllItems().each {
  def my = it
  // MavenModule is superfluous project returned by getAllItems()
  if (!(it instanceof MatrixConfiguration)) {
    println '-->' + it

    println getPropertiesFrom(it)

    if (it.hasProperty(propName) && it."$propName") {
        println 'name: ' + it."$propName"
    //if (it.hasProperty('SCMs') && it.SCMs) {
    //  println '\n' + '===' + getPropertiesFrom(it.SCMs[0])
  println ''

Where is stored the commit sha?

Note: Job1 project is an instance of 'org.jenkinsci.plugins.workflow.job.WorkflowJob'

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 [hidden email].
To view this discussion on the web visit
For more options, visit