Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 424
Daniel Müller Avatar asked Jun 04 '26 21:06

Daniel Müller


1 Answers

From about_Environment_Variables:

Environment variables, unlike other types of variables in PowerShell, are always stored as a string and can't be empty.

Your if statement evaluates to true, because your string variable is not empty. In other words, it contains the string false and not a boolean value. Do a proper string comparison instead:

if ($Env:isModuleUpdate -like 'true') {...
like image 102
stackprotector Avatar answered Jun 07 '26 23:06

stackprotector