Accessing script parameters within C# code template

Hello!

I’m trying to access a custom script parameter within the script’s C# code. The most examples I have seen use PowerShell as the scripting language and I have been unable to find an example with a C# script that references the scripts parameters within the code. Would you be able to give me an example of how I can accomplish this?

Thanks,
MC

Hi MC,

Thanks for reaching out. Could you explain a bit more what you are trying to accomplish so I can give you a proper example? Is your custom script on a Script step within your deployment process, or on a separate file which you are trying to call from another script step?

Thanks!

Dalmiro

Hello Dalmiro,

Thank you for your response. The script is on the “Script step” within the deployment process in the Octopus Project - the one where you can specify a script in one of these 3 languages - Powershell, C# and Bash. The script step also has a “Parameters” tab where custom parameters can be specified and referenced within the script. I’m looking to find out how I can access these parameters within the C# script. I’ve attached a screenshot of the relevant step in Octopus.

Thank you much
MC

octopus.jpg

Hi MC,

Thanks for the explanation! See attached screenshots for a visual reference on how to reference the parameter from your script.

Tip: On the top right corner of the script editor, you’ll see an Icon (see tip.jpg). Click on it, and you’ll see all the variables available for you to use in your script. If you click on the one that references the parameter you want to use (in my case “Name”), Octopus will take care of the syntax for you and insert it in your script.

Hope that helps

Dalmiro

Awesome! Exactly what I wanted. Thank you very much for your assistance!

Regards,
MC