I'm trying to set up a Jenkins project which call a gradle task.
Without jenkins (i.e. from command line), the project compile fine.
However, when I ran it from jenkins, it stop at a particular function that I build to get the total commit number from Git:
def getBuildNumber = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = stdout
}
return stdout.toString().trim()
}
It produces this error:
12:19:44.920 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
12:19:44.924 [ERROR] [org.gradle.BuildExceptionReporter]
12:19:44.927 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
12:19:44.928 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred evaluating root project 'MyProject Bitbucket'.
12:19:44.931 [ERROR] [org.gradle.BuildExceptionReporter] > A problem occurred starting process 'command 'git''
I thought this is caused by jenkins not recognising the command, so I added an export path statement before the execution of the gradle script. However the error still happen.
I'm not sure where I did wrong, If there's an alternative to do this I would be more than happy to try it out.