Escaping environment variables

Hi, I’m deploying a service which receives an environment variable which has a string value that contains ${routedByValue}. This ${routedByValue} represents a string - I don’t want it be replaced with an env var.

I tried to use double dollar sign ($$) but failed, also tried escaping with \ - didn’t work as well.

How can I escape it so it is kept as a string?

Hi @hadaromash !

I imagine you are running okteto deploy to deploy your service, right? can you share with us your manifest and show us where you make use of that env?

Right, I am using okteto deploy.
This is the service definition in the docker-compose.yaml (removed some irrelevant lines):

      CONNECTOR_NAME: chainperks-outbox-connector"
      KAFKA_CONNECT: kafka-connect:8083
          "name": "chainperks-outbox-connector",
          "config": {
            "transforms": "outbox",
            "transforms.outbox.type": "io.debezium.transforms.outbox.EventRouter",
            "": "topic",
            "transforms.outbox.route.topic.replacement": "${routedByValue}",
            "transforms.outbox.table.whitelist" : "chainperks.outbox_events",
            "": "id",
            "transforms.outbox.table.field.event.key": "aggregate_id",
            "transforms.outbox.table.field.event.timestamp": "timestamp",
      - swell-app-mysql
      - swell-app-register-schemas
        condition: on-failure
        max_attempts: 10

The "${routedByValue}" is switched by empty string, where I would like it to be kept as it is.

Hi @hadaromash !

A quick workaround for this could be to escape the envsubst that okteto does internally. Here’s a post with all kinds of different methods, but I think the most appropiate in this case is to write your envvar as


I know it’s not the most elegant, but it should do the work.

May I ask what’s the use case here? Why does the CONNECTOR_CONFIG gets injected partially with ${routedByValue} unset for later?

Agustin, first thanks for your help!

I tried this now, but it is converted to

"transforms.outbox.route.topic.replacement": "\$\{routedByValue}",

I also tried the Dollar trick, by adding another environment DOLLAR=$, but it didn’t work as well since ${DOLLAR} is not being replaced with $`.

Regarding your question - this docker is setting up Debezium which uses this config, this variable is listed here: Outbox Event Router :: Debezium Documentation. I admin that I don’t know much more to elaborate, I’m just trying to setup the environment based on our config in production and locally pre-Okteto time.

@hadaromash sorry, you are right about my previous response that doesn’t work. I got too confident :sweat_smile:

I got to workaround it by creating a .env file with the content:


and in the docker-compose use “${routedByValue}”, therefore the envvar will be replaced by the same text.

Hope this solver your problem!

Hi Agustin, happens to the best :slight_smile:

The workaround of .env does work, however my concern with this approach is that this service is used by many other services as a dependency, so when a dev runs okteto deploy of another service, this .env file won’t be available during the deploy. Another issue is that we use .env in .gitignore so I can’t commit this file for everyone (I can create another parallel committed file though).

I tried to set the variable in a config file and reference the file with env_file:, but it didn’t help either - the env was replaced with an empty string.

Hello @hadaromash ! it looks like we need to work on it. As of today, it is not possible to escape an environment variable with the same approach that docker follows. I have created an issue with it and after addressing it we should be able to solve scenarios like yours. Thank you very much for discovering it!

Hey @hadaromash ! Thanks a lot for your patience and for discovering this unexpected functionality.

While debugging this, I’ve seen that we do the envsubst multiple times, and that’s causing the issue. While we work on the fix, I’ve found a solution to your current use case! Try using


It has worked for me just now. Tell me how did it go :smiley:

This indeed works. Thanks everyone! I’ll take this opportunity to let you know that I like Okteto very much, it’s a game changer in my dev team.

1 Like

Hi guys, how are you? I hope you are well.

I was doing some testing to deploy services for my university and I discover that you can’t add a variable with special characters using the launch environment from the dashboard.
If you do that, you receive deploy command failed: exit status 1 in the console.

mongodb+srv://usr:password@host/db?retryWrites=true&w=majority => exit status 1
mongodb+srv://usr:password@host/db => works.

Do you know is there any workaround for this?
Thanks in advance