Kubernetes Container Shell Command

I’m trying to use the Kubernetes step template to deploy a container that requires I run a command in shell. Specifically, the YAML I want to specify looks like this:

        - name: test
          command: ["/bin/sh"]
          args: ["-c", "export UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/(.{12}).*/\\1/p' /proc/self/cgroup) && dotnet test.dll"]

But the command arguments the step template accepts seem to mangle every attempt to get this in place. For uninteresting reasons I’m not able to use a YAML file deployment for this project, just the “Deploy Kubernetes containers” Step Template.

Trying to follow the instructions in the documentation for the Step Template (here) I’ve not gotten it to generate precisely what I need, its as though the length of the line I’m specifying is too long and it gets broken apart, which isn’t great for this particular string.

I’m at a loss for how I should proceed, can the Step Template achieve what I’m looking for?

Hi Daniel,

Thanks for getting in touch!

Would you be able to provide some further details about the issue you are experiencing?

You mention things getting mangled every time you attempt this. If you could provide some further details about what exactly is breaking here and how, I’ll be better able to help troubleshoot this issue.

If you are seeing an error or broken behaviour, a screenshot would be helpful.

Looking forward to hearing from you and getting to the bottom of this.

Best regards,

Hey Daniel, sure thing!

So I’ve tried several ways of entering the command arguments into the Octopus step, most recently with the following configuration:


Command arguments
"export UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/(.{12}).*/\\1/p' /proc/self/cgroup) && dotnet test.dll"

And here’s the log of what the deployment yaml ended up looking like:

kubectl get deploy test -o yaml

  - args:
    - -c
    - '"export UNIQUE_HOST_ID=$(sed -rn ''1s#.*/##; 1s/(.{12}).*/\\1/p''
      /proc/self/cgroup) && dotnet test.dll"'
    - /bin/sh

So what looks to be happening is the unique_host_id isn’t getting correctly set and it seemingly cannot find the described dll because it’s lost the -c context. The template seems to be putting a pair of single quotes around it then splitting it with a newline right before the 3rd sed argument.

Hi Daniel,

Thanks for following up! Sorry for the delay in getting back to you on this one. My colleague is off currently so I’ll try to help for the time being. :slight_smile:

I think I can see what’s going on here. It comes down to the double quotes in the arguments (in line '"export UNIQUE_HOST_ID=$(sed -rn ''1s#.*/##; 1s/(.{12}).*/\\1/p'' /proc/self/cgroup) && dotnet test.dll"') which are redundant. Each item of that array is treating it as a single argument, which looks like what you’re trying to do by putting in the quotes, so it’s not necessary.

So the short answer is the remove the quotes around the second line in the list of arguments. e.g.

Which then produces this YAML.

I hope this helps! Please let us know how you go or if you have any other questions.

Best regards,


That fixed it! Thanks so much for your help!

Hi Daniel,

Great to hear! You’re welcome, and thanks for the update. Don’t hesitate to reach out if you have any questions in the future. :slight_smile:

Best regards,


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