I have a Jenkins pipeline that invokes a Powershell script via the Powershell plugin. The pipeline uses withCredentials to put the user/password for Powershell to use in SQL connections into variables. I pass them as properties on the command:
def psCmd="./Set-CheckmarxTeams -server ${server} -jkuser $sqluser -jkpass $sqlpass"
The script has them defined as parameters:
param ([string]$server='ad1hfddbst930\shared',[string]$jkuser,[string]$jkpass)
but the SQL connection using $jkuser
and $jkpass
fails. The password has a $
in the middle. I tried to Write-Host $jkpass
and it only shows the part up to the $
, but nothing after it. Do I need to modify the string before passing it in? If so, how?
"Escaping" the dollar sign is easy and good to know. In this case, @Richard Schaefer needed to pass the entire string of a password that included the dollar sign.
Storing a string in the $jkpass
variable like so:
$jkpass = "thisisa$password"
Would output: thisisa
Therefore, storing the password with single quotes eliminates this issue.
$jkpass = 'thisisa$password'
This outputs: thisisa$password