Handle arbitrary large env vars correctly #1090
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
README.md
is updated with the changes (if needed)Version
Requires a MINOR version update
Context
The list of env vars passed to a build can grow really large in some cases. So large that it hits the exec syscall size limit and either the Bitrise CLI process can't be launched, or one of the subprocesses that the CLI launches (envman, step processes, etc.)
This happens most often when one of the Bitrise-generated env vars is huge, such as
$BITRISE_GIT_CHANGED_FILES
or$BITRISE_GIT_COMMIT_MESSAGE
.Changes
Like many other tools, we should support reading env vars from an env file on disk. This requires a change in the agent launching the CLI process, so this remains an optional feature and the fallback mechanism is the same as before.
The main idea behind this change is that once all env vars are saved to a file on disk, the actual env vars in the runtime environment can be cleared so that their size stays below that limit. The CLI just needs to reconstruct the original env vars from this envfile.
There are two areas where env vars are exposed to the user:
run_if
templatesThis PR patches the
getenv
,enveq
andenvcontain
template functions so that they return the original env var values. There should be no breaking change here.Env vars exposed to steps and scripts
It's not possible to expose arbitrary large env vars to the step subprocess because of the syscall limits mentioned above.
Therefore, custom steps are suggested to read the original env value from the env file. We present this warning:
This is going to be a breaking change for some custom scripts and tools. We minimize the impact by:
Also, considering that the builds with env vars above the limit simply do not start today, this is going to be an improvement.
Decisions
We considered truncating env vars (to stay within the system limits), but that would lead to data corruption and hard-to-debug errors for users.
We also considered removing the offending env var altogether (instead of erasing its value), but that seems like a bigger breaking change than keeping the env var with an empty string value.