Replace variables in Raw YAML deployment


I’m having issues with Kubernetes raw YAML deployments because there isn’t a way to dynamically reference a specific version of a image that I want to deploy.
Our deployment pipeline builds a new image for every version that need to be deployed, so I need octopus to take that image version and replace it into the raw YAML specification.

However, it seems you don’t support replacements here, so I’m stuck.
For other stuff, I can deploy configmaps and secrets, but for the image version that’s not an option.

            image: registry.local/job-image:#{Octopus.Action.Package[job].PackageVersion}

As this is a CronJob I’m deploying, I can’t use the regular container deployment step you offer.

Any help or recommendations here?


Hi Silas,

Thank you for reaching out. Sorry to hear that you’re running into this issue dynamically acquiring image versions.

You have unfortunately run into an oversight on our part. Sorry about that. Our engineering team is aware of this and backlogged an item to add a package version option to the “Deploy raw Kubernetes YAML” step.

In the meantime, there is a bit of a hacky workaround that may work for you here. By adding the “Run a kubectl CLI Script Step” to your Build process, you can dynamically capture the image/package version number in this step then apply the variable back to the YAML with the following steps.

  1. Add the " Run a kubectl CLI step" to your process before the Kubernetes Raw YAML Step.


To the Inline Source Code option add the following script (replacing Name and Package with your details):
Set-OctopusVariable -name “AcmeVersion” -value “#{Octopus.Action.Package[Acme].PackageVersion”

Set package reference by choosing your Package ID and option “The package will not be acquired” preventing the package from being downloaded and extracted.

Save the Package reference and CLI step once completed.

  1. Return to your raw YAML step and update the YAML Source with the new package variable.

Script Step Name being the name of the “Run a kubectl CLI step”
#{Octopus.Action[Script Step Name].Output.Package[Acme].PackageVersion}

Give this a try and let me know how it goes.

Thanks again for reaching out regarding this issue.

Thank you,


Thanks for you response

This seems to also rely on replacing variables in the “Deploy raw kubernetes yaml” step, which is the functionality that is not working.

Am I misunderstanding something?

Hey Silas,

Variable substitution is automatically applied to the yaml in the Deploy raw kubernetes yaml step.

It won’t replace any variables which don’t exist, which would explain why the package version wasn’t being replaced in your example (because that step doesn’t allow selecting packages, as Tina mentioned).

Are you seeing existing variables not being replaced?

Aha - I was under the impression that variable substitution did not work at all for that step type, as the variable picker control is not visible, so I was not even looking to try and get the variables right.

This worked fine after actually pointed to the right variablee - thanks!

Hi Silas,
Happy to hear this is working for you.
Don’t hesitate to reach out if you have additional questions.

Happy Deployments!