Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to pass environment variable as value #468

Closed
vikram-katkar opened this issue Jun 16, 2020 · 13 comments
Closed

how to pass environment variable as value #468

vikram-katkar opened this issue Jun 16, 2020 · 13 comments
Labels

Comments

@vikram-katkar
Copy link

Describe the bug
how to pass environment variable as value?

yq w temp.yaml data.role ${VALUE}

@mikefarah
Copy link
Owner

As you would with any other shell command.

export VALUE=cat
yq w temp.yaml data.role $VALUE

@StianOvrevage
Copy link

How is this done on v4, where everything is in a string that will not get expanded by the shell?

@StianOvrevage
Copy link

This works, even though it's a bit ugly:

yq eval ".imageTag = \"$GITHUB_SHA\"" deploy/values-old-dev.yaml > deploy/values-dev.yaml

@bilalinamdar
Copy link

I tried above it just got me the thing i changed. other parameters got DELETED !

@bilalinamdar
Copy link

bilalinamdar commented Aug 3, 2021

for v4 this works

To change with var
myvar="data:/root"
yq eval ".services.app.volumes[0] = "$myvar"" -i docker-compose.yml

-i, --inplace update the yaml file inplace of first yaml file given.

Thanks to above command @StianOvrevage Just need to escape properly.

@sromocki
Copy link

@bilalinamdar

I still had to escape the double quotes in your above response to get it to work

yq eval ".services.app.volumes[0] = \"$myvar\"" -i docker-compose.yml

@bilalinamdar
Copy link

bilalinamdar commented Aug 27, 2021

my mistake was to not include code tag that is why it is messed up in the post.
Apologies for the same. below i copy pasted same line of yours

yq eval ".services.app.volumes[0] = "$myvar"" -i docker-compose.yml

yq eval ".services.app.volumes[0] = \"$myvar\"" -i docker-compose.yml

@CarMoreno
Copy link

In a Dockerfile, I created an ARG called VARIABLE which is set from a docker-compose.yaml file. I used this sentence and it worked:

ARG VARIABLE
yq -i '.this.is.yourproperty = strenv(VARIABLE)' file.yml

@aerlaut
Copy link

aerlaut commented Nov 22, 2022

@CarMoreno that inserts the value as a string right? Is there a way to parse VARIABLE into an integer?

@CarMoreno
Copy link

Yes @aerlaut as string. I did not know a way to parse it into an integer, sorry

@mikefarah
Copy link
Owner

Just use env(VARIABLE) instead :)

@leonarac
Copy link

Just use env(VARIABLE) instead :)

can i get a value from yml file, and store to a variable in a pipeline? im working with azure

@evelizg
Copy link

evelizg commented Sep 6, 2023

Hi @mikefarah
I need your support please.
I put this shell but doesn't work:
yaml is an environment variable
yq -i 'del(yaml)' ejemplo_config.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants