I have having a strange issue with powershell, I have a step to remove a certain file, but it failed to locate that file.
Script:
if (!(Test-Path $FilePath))
{
Write-Error "The file path $FilePath does not exist!"
return
}
When above script ran, The if statement actually returns true, therefore the code block inside the if statement is executed.
I tried to run the same script manually on the target machine locally, it is working fine, no issue. Only encounter errors when run it using the octopus step.
Also if i run the same script using the script console, also working perfectly, just for some reason it does not like it when running it during the step.
Thanks for reaching out! That does seems to your just fine on my end. Could you try the below script and let me know if on the list of files you see the one you are looking for?
[System.IO.DirectoryInfo]$filePath = "Put your full file path here"
$Parent = $filePath.Parent
Write-Output "The parent folder of the file is [$Parent]. The files in that dir on the machine [$($env:COMPUTERNAME)] are: "
$Parent
if (!(Test-Path $FilePath))
{
Write-Error "The file path $FilePath does not exist!"
return
}
else{
"The file exists"
}
Also please let me know which version of Powershell is that VM running.
After days of struggles, I could not identify the root cause of the issue, however, if I delete the step, and create it again, then it works flawlessly. I have noticed this strange behavior for at least two times, I believe it is a bug within Octopus software itself.
Thank for the heads up. Unfortunately without being able to consistently reproduce this behavior, its hard for us to pin point the issue and fix it. We’ll keep our eyes open for similar reports to this and see if those help us reproducing this.