xml1ra
Last Updated: July 13, 2016
·
701
· superboum
Avatar1

Jenkins Pipeline Error "Cannot run program "cmd" : CreateProcess error=87, The parameter is incorrect"

If you have the following error in Jenkins while trying to execute a batch script in a witchCredentials block :

java.io.IOException: Cannot run program "cmd" (in directory "C:\somewhere"): CreateProcess error=87, The parameter is incorrect

That's probably because you binded one of the value to a a null environment variable. For example, the following code will fail

// WILL FAIL
withCredentials([[
    $class: 'UsernamePasswordMultiBinding', 
    credentialsId: 'mycreds', 
    passwordVariable: '', 
    usernameVariable: 'USERNAME'
]]) {
    bat "hello"
}

But if you assign an environment variable to the password, it will works.

// WILL WORK
withCredentials([[
    $class: 'UsernamePasswordMultiBinding', 
    credentialsId: 'mycreds', 
    passwordVariable: 'NOT-USED', 
    usernameVariable: 'USERNAME'
]]) {
    bat "hello"
}

I hope it will help someone :D

Say Thanks
Respond
Filed Under