powershelljenkinsparametersjenkins-pipelineboolean

Jenkins (Pipeline) Boolean Parameter in Powershell confusing


I have a parametrized Jenkins Pipeline Script, where I pass a Boolean Parameter "isModuleUpdate".

When I use this parameter in my Pipeline Script I get confusing results. My Script:

 Write-Host ">>> isModuleUpdate as String: $Env:isModuleUpdate"
 Write-Host ">>> isModuleUpdate as Variable: " $Env:isModuleUpdate
 if ($Env:isModuleUpdate) {
      Write-Host ">>> ModuleUpdate is checked!"
 }

When I run my Script, the Result is:

>>> isModuleUpdate as String: false
>>> isModuleUpdate as Variable: false
>>> ModuleUpdate is checked!

What is the sexiest way to check this variable corectly?


Solution

  • I recall having issues with checking booleans in PowerShell as well. Ultimately, -eq $true worked:

     if ($Env:isModuleUpdate -eq $true) {