ENV vars not showing up in workflow?

Hello!

I’m currently using a curl command to trigger a bitrise build:

curl https://www.bitrise.io/app/XXXXXXX/build/start.json \
--data '{"hook_info":{"type":"bitrise","api_token":"XXXXXXXX"},"build_params": {"tag":"XXXXXXXX"},"environments":[{"mapped_to":"SOME_ENV_VAR","value":"1234","is_expand":true}]}'

In the workflow that gets kicked off for the resulting build, I have a script step that does this:

#!/bin/bash
set -ex

# write your script here
echo "value = $SOME_ENV_VAR"

but all I see in the logs are:

+ echo 'value = '
value =

Why is the SOME_ENV_VAR not showing 1234 in the logs when the script step gets run?

Even when I echo the environment vars list with “printenv”, I don’t see it in the logs, either.

From what I understand, these APP ENV vars should be available in the workflows…What exactly am I missing?

2 Likes

I had the wrong nesting for the json data I was posting:

It should look like this:

--data '{"hook_info":{"type":"bitrise","api_token":"XXXXXX"},"build_params":{"tag":"XXXXXXX","environments":[{"mapped_to":"SOME_ENV_VAR","value":"1234","is_expand":true}]}}'

3 Likes

Just for future reference, it’s also worth to mention that you can’t overwrite env vars defined in your config (bitrise.yml) with API defined env vars just by specifying the env var through the API call.

If you want to do that please follow this guide:

1 Like

Could we get this added to the docs?

Currently the example is as follows with no mention that it should be a property of build_params:

"environments":[
  {"mapped_to":"API_TEST_ENV","value":"This is the test value","is_expand":true},
  {"mapped_to":"HELP_ENV","value":"$HOME variable contains user's home directory path","is_expand":false},
]
1 Like

Hi @nmwilk,

The docs are open source. Please feel free to file a pull request over on https://github.com/bitrise-io/devcenter.

It will be good that the documentation clarifies that environments should be inside of build_params… I lost a couple of hours just trying to figure out why this didn’t work:

{
	"hook_info": {
		"type": "bitrise"
	},
	"build_params": {
		"branch": "the-pr-branch",
		"branch_dest": "master",
		"pull_request_id": 133,
		"skip_git_status_report": "true"
	},
	"environments":[
  		{"mapped_to":"API_TEST_ENV","value":"This is the test value","is_expand":true},
  		{"mapped_to":"HELP_ENV","value":"$HOME variable contains user's home directory path","is_expand":false},
	]
  }

It is not really clear from the documentation that it should be:

{
	"hook_info": {
		"type": "bitrise"
	},
	"build_params": {
		"branch": "the-pr-branch",
		"branch_dest": "master",
		"pull_request_id": 133,
		"skip_git_status_report": "true",
		"environments":[
  			{"mapped_to":"API_TEST_ENV","value":"This is the test value","is_expand":true},
  			{"mapped_to":"HELP_ENV","value":"$HOME variable contains user's home directory path","is_expand":false},
		]
	}
}