2021-01-09 00:33:39 +00:00
|
|
|
|
2021-01-09 01:06:19 +00:00
|
|
|
## Read string environment variable
|
|
|
|
Running
|
|
|
|
```bash
|
|
|
|
myenv="cat meow" yq eval --null-input '.a = env(myenv)'
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
a: cat meow
|
|
|
|
```
|
|
|
|
|
|
|
|
## Read boolean environment variable
|
|
|
|
Running
|
|
|
|
```bash
|
|
|
|
myenv="true" yq eval --null-input '.a = env(myenv)'
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
a: true
|
|
|
|
```
|
|
|
|
|
|
|
|
## Read numeric environment variable
|
|
|
|
Running
|
|
|
|
```bash
|
|
|
|
myenv="12" yq eval --null-input '.a = env(myenv)'
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
a: 12
|
|
|
|
```
|
|
|
|
|
|
|
|
## Read yaml environment variable
|
|
|
|
Running
|
|
|
|
```bash
|
|
|
|
myenv="{b: fish}" yq eval --null-input '.a = env(myenv)'
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
a: {b: fish}
|
|
|
|
```
|
|
|
|
|
2021-01-09 00:33:39 +00:00
|
|
|
## Read boolean environment variable as a string
|
|
|
|
Running
|
|
|
|
```bash
|
2021-01-09 01:06:19 +00:00
|
|
|
myenv="true" yq eval --null-input '.a = strenv(myenv)'
|
2021-01-09 00:33:39 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
2021-01-09 01:06:19 +00:00
|
|
|
a: "true"
|
2021-01-09 00:33:39 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Read numeric environment variable as a string
|
|
|
|
Running
|
|
|
|
```bash
|
2021-01-09 01:06:19 +00:00
|
|
|
myenv="12" yq eval --null-input '.a = strenv(myenv)'
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
a: "12"
|
|
|
|
```
|
|
|
|
|
|
|
|
## Dynamic key lookup with environment variable
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
cat: meow
|
|
|
|
dog: woof
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
|
|
|
myenv="cat" yq eval '.[env(myenv)]' sample.yml
|
2021-01-09 00:33:39 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
2021-01-09 01:06:19 +00:00
|
|
|
meow
|
2021-01-09 00:33:39 +00:00
|
|
|
```
|
|
|
|
|