Problem in getting updated variable value from previous step

Hi Team,
Could you provide me sample for getting updated variable value from previous step which does not exist at the start of deployment.

Hi,

Thanks for getting in touch! Output variables allow you to create variables during your deployment process, which you use in subsequent deployment steps. For an example in PowerShell, you can create the variable in a step using Set-OctopusVariable -name "VariableName" -value "YourValue" which can be called in a later step like this: $VariableName = $OctopusParameters["Octopus.Action[StepName].Output.VariableName"].

We have great documentation around output variables, with examples in various languages (PowerShell, C#, Bash, F#).
https://octopus.com/docs/deploying-applications/variables/output-variables

Some additional in depth info can be found in our Fun with output variables blog post. :slight_smile:

I hope this helps! Don’t hesitate to reach out if you have any further questions.

Best regards,

Kenny

Thanks, this is very informative and helpful.

But I am looking for how do we create output variable using OctopusClient API https://www.nuget.org/packages/Octopus.Client/

Do you have any samples for this?

Hi,

Thanks for following up! Unfortunately it’s not possible via the Octopus.Client. Setting output variables is a Calamari feature, and they would need to be created inside of the deployment. What are you trying to achieve? We may have a more straightforward answer to help you get there. :slight_smile:

I look forward to hearing back!

Best regards,

Kenny

Hi,
Thanks for reply.
we are trying to provide HOST_PORT from our C# console application and the application is being called from inside octopus powershel. Once c# application finds next available port it update the octopus variable so that next step which is to “Deploy on IIS” can take that variable and deploy the application on the port returned by C# console application.
Problem is that however octopus variable HOST_PORT is getting updated but updated value is not assigned as a port while application is deployed in the next step.

Please suggest to fix this issue.

Thanks
Rkumar

Hi Rkumar,

Thanks for following up and expanding a bit on your scenario. There are a few different possible options to pass the port information from your console app to an Octopus variable.

  1. In a run a script step, using ScriptCS you can reference your console application as you would an assembly (dll) and call it to do the port logic, and then store the returned value in a variable.
    Reference syntax for ScriptCS: https://github.com/scriptcs/scriptcs/wiki/Writing-a-script#referencing-assemblies

  2. Return the result (port) from the application to a PowerShell script, then use the PS script to set the variable.

  3. Script the application in Octopus. This script could then set the output variable.

I hope this helps! Let me know if you have any further questions.

Kind regards,

Kenny

Hi,
Thanks for your valuable reply.
I was just trying to call a web api inside octopus power shell like
$R = Invoke-WebRequest -URI http://www.bing.com?q=how+many+feet+in+a+mile
but got the below error
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer’s first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.

Could you provide the cause of the issue and how i can fix it. if possible please provide the working example.

Hi Rkumar,

You’re very welcome! Using the Invoke-WebRequest cmdlet requires you to first start Internet Explorer. Otherwise, if IE isn’t installed on your computer, the parameter -UseBasicParsing is required to run this, as your error message is referring to. You can see more information on Microsoft’s doc page. :slight_smile:

Microsoft additionally introduced another cmdlet called Invoke-RestMethod, which is what we would recommend using here. You can see more details on Microsoft’s docs.

I hope this helps! Let me know if you have any further questions.

Best regards,

Kenny

1 Like