This is a Jenkins pipeline script running on a Windows Server 2016 node
stage('clone') {
steps {
script {
dir("${WORKSPACE}") {
if (fileExists("foobar")) {
echo 'Updating workspace for Foobar application'
dir ("${WORKSPACE}/foobar") {
bat ("git fetch origin master")
}
} else {
echo 'Building Workspace for Foobar Application'
def command="git clone -c http.extraHeader='Authorization: Bearer <HTTPACCESSToken>' https://myserver:port/scm/psrc/foobar.git"
bat ("${command}")
}
}
}
}
}
The string in the ‘command’ variable is correctly constructed and echoed to the build log. I can copy that echo into a PS terminal and the command executes perfectly. It also works perfectly in a plain DOS terminal.
However in Jenkins pipeline, the string is NOT properly parsed into DOS and I get:
fatal: Too many arguments.
usage: git clone [<options>] [--] <repo> [<dir>]
-v, --[no-]verbose be more verbose
-q, --[no-]quiet be more quiet
I can solve that issue with escaped double quotes surrounding the parameter for -c but then the GIT command does not properly use the header and I get a username prompt.
I am completely stuck right now. I have tried every possible manner of quoting and escaping of quotes and can not get this to work.