Bamboo Data Center build fails because the environment block used to start a process cannot be longer than X bytes

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Build plans fail to run and the following appears inside the log file produced by the build:

The environment block used to start a process cannot be longer than 65535 bytes.  Your environment block is 67476 bytes long.  Remove some environment variables and try again.

You might also see builds running but throwing the following warnings in the build logs and <agent-home>/logs/atlassian-bamboo.log:

Variable bamboo_VARIABLE may be too long, make sure that the builder environment variable values are as expected
The size of environment is 97652, make sure your build environment handles this correctly 

Environment

The solution has been validated in Bamboo 9.2.17 but may be applicable to other versions.

Diagnosis

Builds fail to run and the following errors are present in the build logs:

build	23-Feb-2016 11:37:01	System.InvalidOperationException: The environment block used to start a process cannot be longer than 65535 bytes.  Your environment block is 67476 bytes long.  Remove some environment variables and try again. 
build	23-Feb-2016 11:37:01	   at System.Diagnostics.EnvironmentBlock.ToByteArray(StringDictionary sd, Boolean unicode)
build	23-Feb-2016 11:37:01	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
build	23-Feb-2016 11:37:01	   at System.Diagnostics.Process.Start()
...

When builds are not failing, other symptoms are the presence of the following warnings in the build logs and in the logs of the agent that ran the build (<agent-home>/logs/atlassian-bamboo.log):

INFO   | jvm 1    | 2024/10/02 09:55:21 | 2024-10-02 09:55:21,269 WARN [0-BAM::remote-agent.com (4)::Agent:pool-4-thread-1] [EnvironmentVariableAccessorImpl] The size of environment is 97652, make sure your build environment handles this correctly
Variable bamboo_VARIABLE may be too long, make sure that the builder environment variable values are as expected

The environment block is where environment variables are stored. Please bear in mind that Bamboo does not impose any limits. Build systems such as Bamboo tend to generate environment variables, and therefore checking this information during the build process would be the best way to determine what the problem is. If you are able to capture the error and output the environment (by running "env" in CMD or Powershell and also creating a script task in Bamboo to execute "env") you can compare the number of variables you have in your system versus what Bamboo is exporting to your system - it may lead to further insights.

Cause

The maximum size of the environment block in Windows systems seems to be 32,767 characters. Assuming every character has 2 bytes, this would give us the ~65k bytes. If you're getting this error it means you're exceeding the environment block size.

Solution

There are a number of ways to workaround this problem, and this will depend on what's actually causing it:

  1. Check the amount of variables you have in your system (without using Bamboo) by running "env" in CMD or Powershell while logged in as the same user account that runs Bamboo/the remote agent.
    1. If you have a large list of Windows Environment Variables, please consider trimming it down.
    2. If it's not a large list, then it's most likely the variables generated as part of the build process that are causing the problem. Please proceed to step 2.
  2. To see a full list of the environment variables from a build, you can add the Dump variables to log task to the build plan. Once you've run the build with this task added (preferably as the first task of the plan). You can check the build logs for the full environment varaibles info.
  3. Upon executing the step above, if you identify the problem is part of the build process, please check the amount of Global Variables you have listed in Bamboo. Since all Global Variables are exported to the server during the build process, consider using environment variables at a Plan, Project or Deployment Project level instead, as they are only loaded into the environment when required and not for all builds.
  4. If you are using Plan/Deployment Project variables and only keeping Global Variables for what you need across your entire Bamboo instance, you should consider trimming down the amount of Plan/Deployment Project variables.

Last modified on Jan 3, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.