Search code examples
stringpowershellbooleanoctopus-deploy

Convert string to boolean in powershell


I have a script to upload a package to Octopus and I am using delta compression and I am getting the following fail: Cannot process argument transformation on parameter 'DeltaCompression'. Cannot convert value "System.String" to type "System.Boolean". I am using the Delta Compression in my push call, I have set $DeltaCompression to type bool so I am not sure why it is saying convert string to boolean in the failure message. Can someone show what is wrong or a fix for this? Thanks.

Code:

#Function to push packages to Octopus

function PushPackage {
param(
    [string]$OctopusUri,
    [string]$ApiKey,
    [string]$Package,
    [bool]$DeltaCompression
)

try{ 
   $tries=1
   do 
   {
    Write-Host "Pushing $Package to Octopus"
    & $OctoExePath push --package $Package --server $OctopusUri --apiKey $ApiKey --use-delta-compression $DeltaCompression --logLevel 'verbose'

    $tries++
    }until($LASTEXITCODE -eq 0 -or $LASTEXITCODE -eq $null -or $tries -gt 5)
}
catch{
      $failMessage = "$($_.Exception.ToString()).$($_.InvocationInfo.PositionMessage)"
      Write-Host "PUSH PACKAGE Exception--------- $failMessage"
    }
}

$Package = "C:\temp\OctoTest\MyTestPackage.1.0.0.zip"
$OctoExePath = "C:\Users\QVL6\Downloads\OctopusTools.7.3.7.win-x64\octo.exe"
$DeltaCompression = "$false"
$ApiKey = "API-CRW9JBMJG8Z6ONIOATU16PVVV5E"

PushPackage $OctopusUri $ApiKey $Package $DeltaCompression

Solution

  • You have to replace the line.

    From :

      $DeltaCompression = "$false"
    

    To :

     [bool]$DeltaCompression = $false;