The Jenkins node is a Windows agent, which has Git Bash installed.
I need to execute a git command inside a workspace folder that is already setup as a git folder. Due to the simplicity of the git command (say 'git branch'), we do not want to create an entire .sh file and opted for inline shell command like below.
//.groovy
dir ("c:/workspace/project@script/git-folder") {
def git_cmd = sh(script: "git branch", returnStdout: true).trim()
}
The above code works for our other linux nodes. However on this Windows node, Jenkins returned a Shell Script error "c:/workspace/project@script/git-folder@tmp/durable-8xxxxx/script.sh: line 1: git: command not found"
Why did it create the @tmp folder and executing the script inside there and not the intended folder? I checked the agent and looks like both "git-folder" and "git-folder@tmp" are in c:/workspace/ adjacently
I tried to remove the "dir" command and just cd into the path within the script as below
def git_cmd = sh(script: "cd c:/workspace/project@script/git-folder; git branch", returnStdout: true).trim()
but now the error is "c:/workspace/project@2@tmp/durable-6xxxxx/script.sh: line 1: git: command not found"
Found a Jenkins issue thread very similar to my problem, but no clear solution from that.