Running a exe via Octopus PowerShell

HI,
We have a step in our pipeline which runs an executeable.

The inputo the executeable is construct using :

$currentReleaseNumber = $OctopusParameters[“Octopus.Release.Number”]
$InitialReleasePath = $OctopusParameters[“Octopus.Action[Push Package into the box].Output.MyReleasePath1”]
$start = ‘vNext "VRCares’
$end = '" Done product:Cares update PROD ’
$email = ‘“itdev@random.com”’

$output = “$start $currentReleaseNumber$end $email”

Write-Output $output

CD “$InitialReleasePath\ReleaseManager”
.\TFSReleaseManagement.exe $output

Example input:
vNext “VRCares 2022.03.03.213” Done product:Cares update PROD “itdev@random.com

When the output is printed out it is correct but when it is pushed into the exe program we get a index out bound error.

Note: if i take the printed output and run it with the executeable manually it works.

Can you spot what is wrong, as this used to work before with Octopus. Recently it stopped working.

Script output:

Hi @amushtaq

Thanks for messaging us today,

One thing you could try is using the following code in your script:

& '.\TFSReleaseManagement.exe' @("$start", "$currentReleaseNumber$end", "$email")

Hopefully this helps, but feel free to message us for anything else.

Kind Regards,

Dom.

Hi Dom,

Thank you for you quick response!
That did not work.
Any other suggestions?

Hi @amushtaq

I think I have found the mistake try using the same as what had originally but do the following:

.\TFSReleaseManagement.exe "$output"

If that fails you can try:

& '.\TFSReleaseManagement.exe' @("$start$currentReleaseNumber$end","$email")

Hopefully this helps,

Kind Regards,

Dom.

Hi @amushtaq

Sorry for the double message but it might be worth using echo to print out the $OctopusParameters to make sure you have the requested variable for this:

$InitialReleasePath = $OctopusParameters[“Octopus.Action[Push Package into the box].Output.MyReleasePath1”]

Hope this helps,

Kind Regards,

Dom.

Hi Dom,

Both did not work.

Check screenshots attached.

Is there any other Octopus templaetes, I could potentially use?


Hey @amushtaq,

You might have more luck if you define your output var as an array rather than defining an array in your args. I did some local testing and was able to get my output to succeed using that method. The script below should help you modify your script to fit.

$currentReleaseNumber = $OctopusParameters["Octopus.Release.Number"]
$initialReleasePath = "C:\Program Files\Octopus Deploy\Tentacle"
$arg1 = "show-configuration"
$arg2 = "--instance=Tentacle"

$output = @($arg1, $arg2)

Write-Output $output

CD "$initialReleasePath"
& .\Tentacle.exe $output

You could even add your email as a third value in that array and pass only the $output var to the command line exe.

I hope that works for you. Let us know how you progress.

Best,
Brent

Hi @brent_kinney ,

Thank you for you reply.
I did try the method you suggested. Unfotunately that did not work.

see below:


Valid input will be :
vNext VRCares 2022.03.03.213 Done product:Cares update PROD itdev@random.com

Looking forwad to hearing back from you.

Thanks,
Ajwad

Hi @amushtaq

Thanks for getting back to us, please could I just confirm that the issue is with:
Index was outside the bound of the array

Or is it with No Items to report

If it is with the first please could we try break down the script to see where it has the issue, by only running the first two lines of the script as that will most likely point to an index out of bounds error?

Kind Regards,

Dom.

Morning @dom.richardson ,
The issue is with Index was outside the bound of the array.

I have ran the code below:
$currentReleaseNumber = $OctopusParameters[“Octopus.Release.Number”]
$InitialReleasePath = $OctopusParameters[“Octopus.Action[Push Package into the box].Output.MyReleasePath1”]
Write-Output “Current Release Number:$currentReleaseNumber”
Write-Output “InitialReleasePath:$InitialReleasePath”
CD “$InitialReleasePath\ReleaseManager”

The output is:

Current Release Number:2022.3.17
InitialReleasePath:C:\Octopus\Applications\STA-QC01\Cares\2022.03.04.197_2

Is there a possibility of us arranging a call and figuring this out.

Thanks,
Ajwad

Hi @amushtaq

Thanks for the reply, would be able to run the following powershell script on the deployment target to check that it works correctly on the target?

$currentReleaseNumber = "2022.3.17"
$InitialReleasePath = "C:\Octopus\Applications\STA-QC01\Cares\2022.03.04.197_2"


cd "$InitialReleasePath\ReleaseManager"
.\TFSReleaseManagement.exe vNext "VRCares 2022.03.03.213" Done product:Cares update PROD "itdev@random.com"

You also mentioned that it was working before, whats changed? Did you upgrade Octopus?

Is the executable TFSReleaseManagement.exe something that was created by you or is it publicly available?

Kind Regards,

Dom.

Hi @dom.richardson
That worked.

TFSReleaseManagment.exe is written by us.

We opened the firewall rule for our Octopus server to connect and download community steps, since than it has stopped working.

Thanks,
Ajwad

Hi @amushtaq

Great that’s working would you be able to copy that script into the deployment step and test that?

Thanks,

Dom.

Hi @dom.richardson

That worked.

Thanks,
Ajwad

Hi @amushtaq

Great now try the following in your deployment process:

$currentReleaseNumber = $OctopusParameters["Octopus.Release.Number"]
$InitialReleasePath = $OctopusParameters["Octopus.Action[Push Package into the box].Output.MyReleasePath1"]


cd "$($InitialReleasePath)\ReleaseManager"
.\TFSReleaseManagement.exe vNext "VRCares $($currentReleaseNumber)" Done product:Cares update PROD "itdev@random.com"

Thanks,

Dom.

Hi @dom.richardson ,

This is working now thank you.

Any explanation on why the initial syntax stopped working?

Thanks,
Ajwad

Hi @amushtaq

I’m glad we managed to get it working now, I think it was the way PowerShell was passing the arguments to the TFSReleaseManagement.exe executable.

Any other issues please feel free to reach out to us again.

Thanks,

Dom.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.