How to get commitHash from windows slave

Viewed 86

So far I used the below code for getting the commitHash in my JenkinsFile.groovy from linux slaves:

def commitHash = sh(returnStdout: true, script: "git rev-parse HEAD").trim()

Now I'm running on windows slave. How can I modify this command to run on windows as well through CMD?

1 Answers

The very same command should work with a bat step

def commitHash = bat(returnStdout: true, script: "git rev-parse HEAD").trim()

You only need to make sure git.exe is in the agent %PATH%.

You can have a dedicated pipeline for 'Windows' agents (agents with the label 'Windows') in order to execute those OS-specific steps orchestrated by the controller.

Related