1

I'm very new to Jenkins.

enter image description here

I'm using this built-in plugin to do Git Checkout with my GitHub credentials, what I wanna achieve is somehow get the git commit id as a variable so that I can use that commit id on any build step of my pipeline.

I searched but couldn't find any documentation for this plugin.

pipeline {
    agent any

    stages {
        stage('Git Checkout') {
            steps {
                git(
                    branch: 'dev', 
                    credentialsId: 'Aniket-IN-Github', 
                    url: 'https://github.com/ComputerReflex/ComputerReflex-Laravel-React.git'
                )
                 # Want to get the commit id.
                echo "Git Commit # ${GIT_COMMIT}"
            }
        }
    }

}


Thank you so much in advance :)

Subham Manna
  • 103
  • 1
  • 12

1 Answers1

0

you can use this after checkout ( kind of workaround)

env.GIT_COMMIT = sh(script: "git rev-parse HEAD ", returnStdout: true).trim() 
echo env.GIT_COMMIT
oTolev
  • 231
  • 1
  • 2
  • 10