Step Templates using C#

We currently have a step template that notifies our deployment slack channel that is written in power shell. The problem is that any deployments to a linux machine, this step will not run since power shell does not exist for linux and the step will fail for that machine.

I’m attempting to convert this step to c# so that it can be executed on the linux machine as well. Is it possible to include 3rd party libraries in this code to make things easier? For example, Json.NET? From what I can tell it’s using scriptcs.

Hi Luke,

Thanks for getting in touch!

The short answer is that we don’t provide a way to include any third party libraries with your ScriptCS scripts.

However, I think you can load other assemblies at runtime with a r# directive. That way, you could either deploy them in a previous step, or preinstall them on the target machines prior to running the script, then reference them in your script.

Let me know how you go.

Kind Regards,

The binaries that are loaded dynamically have to be in the same directory as the referencing script - I looked around and didnt see any Octopus variables for the script location - can you help provide that?


Hi Justin,

Thanks for the reply.

This is a tricky one. I can’t think of a way to get the working folder of a future script step. When it runs, it will start in a timestamped folder underneath the Tentacle’s Work folder and I don’t think we’ll be able to get that folder ahead of time.

As an alternative, you could create a step template based on a package step rather than a script step and include the 3rd party dlls in that nuget package. You can use the “Custom deployment scripts” feature to set some ScriptCS scripts to run after deployment of the package.

I’ve tested this and it seems to work both in Windows and over an SSH connection to a Ubuntu machine. The dlls in the nupkg file will get copied to the scriptcs_bin folder which is where the script will run.

I hope that helps!