Jenkins 2.x pipeline: how to get git details after checkout?

2,633 views
Skip to first unread message

thomas....@teamaol.com

unread,
May 11, 2016, 3:31:09 AM5/11/16
to Jenkins Users
How do I get the git information right which were - in the past - provided by Jenkins Git plugin?

I have found one information here: https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/gitcommit/gitcommit.groovy
You see that in the code below (extract).

I have the treeish (job parameter which refers to a git tag name or git branch name).

What I'm still missing ... let's say since last build there might have been (n=5) commits.
So I would like to have the "n" commit messages. I know how to get the last "n" log messages in Git ...
...but how do I know how many commits have been since last build?

I see from the stage view (left side, row labels) that the pipeline definitely knows about
the number of commits and even it knows the git details showing them in a tooltip when
I move with the mouse cursor above the label.

How can I get this information after the checkout?

Kind Regards,
Thomas

APPENDIX:

    // ...

    // Retrieving first 6 characters of the SHA Git commit id.
    def getCommit() {
        def command="git rev-parse HEAD > " + this.workspace + "/GIT_COMMIT"
        script.sh(command)
        script.readFile(this.workspace + "/GIT_COMMIT").take(6)
    }

    // ...

    stage 'Get Code'
    checkout([$class: 'GitSCM', branches: [[name: treeish]],
    doGenerateSubmoduleConfigurations: false,
            submoduleCfg: [],
            userRemoteConfigs: [[credentialsId: 'XXXXXXXXXXX_CREDENTIALS',
             url: 'ssh://git@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxt']]])



Reply all
Reply to author
Forward
0 new messages