How to set environment in a remote pipeline

With a “regular” okteto deploy we can control the pipeline through environment variables. This can be done as far as I know by either running:

ENV_VAR=xxx okteto deploy

or by running:

okteto deploy -v ENV_VAR=xxx

However when we specify an image in the deploy section, and therefore run a remote pipeline, the environment variables do not seem to be propagated to the remote environment. Therefore I am not able to control the flow of the remote pipeline through environment variables.

Thus when the deploy section looks as following:

deploy:
  image: IMAGE
  commands:
    - echo $TEST_VAR

And then run:

okteto deploy -v TEST_VAR=test-value

then the value of TEST_VAR in the remote pipeline will not be set.

How can I pass environment variables to a remote pipeline?

Hi @florisie

I’ve been able to make it work with the last option you mentioned in okteto CLI 2.16.4 and 2.17.0

# okteto.yml
deploy:
  image: busybox
  commands:
    - echo $TEST_VAR
$ okteto deploy -v TEST_VAR=test-value 
 i  Using endpoints-test @ okteto.agustin.dev.okteto.net as context
 i  Build section is not defined in your okteto manifest
 i  Running stage 'echo $TEST_VAR'
Executing command 'echo $TEST_VAR'...
test-value
Command 'echo $TEST_VAR' successfully executed

Note that ENV_VAR=xxx okteto deploy is not working for me either.

I have no idea what I did wrong before. I mean, I believe I have tried exactly those ways as described in my question (and thus also the way as you describe in your answer) but I could not get it to work at the time when I wrote this question. Now I try it again to verify that indeed it does not work for me (without updating, I’m still on okteto cli 2.16.2) but now suddenly it works.

Again, no idea what I was doing wrong/different at the time that I wrote this question but I’m happy to learn that it actually does work, even on a previous version of okteto cli.

Thank you for taking the time to test it and showing me that it actually just works!

Your welcome!

Here’s the docs to the usage of the -v command (or --var) Okteto CLI | Okteto Documentation

In case you think there’s something to add, you can propose a PR to GitHub - okteto/docs