Issue
GIT_COMMIT is returning null, so I tried to run the following command:
env.GIT_COMMIT = sh(script: "git rev-parse HEAD", returnStdout: true).trim()
I am now getting the following error:
fatal: not a git repository (or any of the parent directories): .git
I do have my git repo in my Jenkins workspace. Where am I supposed to run the shell script? I have multiple stage looking like:
stage('Checkout GIT')
stage('Do something else')
stage('Do an other thing')
I've been trying to run the shell command in one of these 2 last stages
Solution
You can also specify the location of your repo by wrapping your git commands into dir:
stage('Checkout repo') {
steps {
dir ("{env.WORKSPACE}/<path_to_repo>") {
script {
<your code here>
...
Answered By - Sparkle