Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Access private runner host environment variables


We are utilising self hosted runners, with a runner located in each of our environments (dev, staging, prod, etc). Each of the runner hosts is built with a handful of global environment variables configured, that provide some general configuration for the environment in question (e.g. AWS_DEFAULT_REGION, ENVIRONMENT_NAME, etc).

Is there a way to pass these variables into the container used to run a step on those runners, the use case being that steps would inherit configuration, simply by virtue of the runner they are assigned to? (Similar to setting and using environment variables on individual Jenkins nodes) I would rather avoid having to duplicate this configuration inside BitBucket or having to maintain functionality inside the container to pull this info in from another source, if possible.

2 answers

I would likewise love to be able to get an environment variable from the outer orchestrator container to the inner step container so I could make use of IAM Role derived credentials within my pipelines instead of having to use static credentials from an IAM User...

0 votes

Hi @clockworknet and welcome to the community.

In order to provide isolation and reproducibility, a runner doesn’t provide access directly to the host file system, so I'm afraid that what you're asking is not possible.

You can either set these variables in Bitbucket or pass the values in a file and then source the file during the build.

Kind regards,

Hi Theodora,

 I am suspecting that what I am asking about is not possible, but to be clear I am not asking for filesystem access. I am asking whether it is possible to pass environment variables that are set in the runner host globally, into the container started for each build step - the equivalent of:

`docker run -e SOME_GLOBAL_ENV_VAR ...`

Hi @clockworknet,

Thanks for the clarification, I didn't realize that you were talking about passing the environment variables in the 'docker run' command for the runner.

Please allow me to check with my team internally and I'll get back to you on that.

Kind regards,

Hi Theodora,

Thanks for looking into this further.

It is not the runner container that I am concerned about getting the environment variables into. I start that container and so have full control over the options that are used to start it.

It is each container that is started by the runner process, to handle a deployment step. I guess that if it were possible, those variables would need to be first passed into the runner container, but I am interested in whether it is possible to then get that process to pass them on to each container it starts.

Norbert C Atlassian Team Nov 23, 2021

Hi @clockworknet 

Let me step in, I'm Norbert and I'm also a Bitbucket Cloud Support Engineer, it's nice to meet you.

I would like to inform you that the functionality what you would like achieve is unfortunately not possible. The only way how you can pass the environmental variables to the runner container is to set those variables in your Bitbucket Pipelines settings and once it's set up, those variables can be used in your build.

Please let me know if my explanation was clear and whether if you have any further question?

I'm looking forward to hear from you.

Have a great day ahead!

Best Regards,
Atlassian Bitbucket Cloud Support Engineer

Ajay _view26_ Community Leader Nov 25, 2021

HI @Norbert C ,

Could you provide a sample example? 

I presume you are referring to using them as variables inside the pipeline.



Norbert C Atlassian Team Nov 26, 2021

Hi Ajay,

Yes, of course please find the example :) .

I've created an "asdf" environmental variable with the value of "testtesttest" in Pipelines:


When I started this Pipelines, as you can see I'm using Runners and when I echo the "asdf" environmental variable, it shows the "testtesttest" value:


Please let me know whether if this is the functionality what you're looking for?

Best Regards,

Atlassian Bitbucket Cloud Support

Thanks @Norbert Cfor clarifying the situation - it would be a nice feature to have at some point if possible.

Norbert C Atlassian Team Dec 01, 2021

Hi @clockworknet 


Can you clarify please what feature would you like to have implemented? Would you like to be able to pass the environmental variable via the docker run command? 

Once I have the clarification, I'm going to open a feature request for you.


I'm looking forward to hear from you.


Best Regards,

Atlassian Bitbucket Cloud Support 

Hi @Norbert C 

Our particular use case:


  • we use existing automation and cfg mgmt to build our private runners hosts (in our case AWS EC2 instances), and deploy the BB Runner container instance (there is one small manual step in registering the runner in BB, where we need to copy the various tokens from BB)
  • as part of this automated provisioning, we set a series of environment variables on the EC2 host. The values are typically derived from the AWS environment (e.g. tags added to the EC2 instance/param store values, etc) or otherwise stored in our existing cfg mgmt systems

We would like a way for those host based environment variables to be accessible inside the container used to run each deployment step. With this, we would be able to pass configuration to the deployment step implicitly, simply based on which runner the step was executing.

Without this feature, our options are to create duplicate config inside of BitBucket, however that is inefficient and can also result in having to store/manage values that we would prefer remain inside our environments. Alternatively, we can re-run the same process on each deployment step that we ran when the host was booted to replicate the behaviour and set the env vars inside the step container, but in the context of a fast feedback system, that is somewhat slow.

I guess the 'runner' container would need to be involved given I presume it is responsible for starting the 'deployment step containers' so perhaps being able to pass it a series of env vars with a specific prefix (much like TFVARS in Terraform ) that it will in turn set on the step containers could be an option?

Norbert C Atlassian Team Dec 06, 2021

Hi @clockworknet 

I appreciate your detailed explanation. Unfortunately this is not available right now, but I opened the following feature request:

BCLOUD-21523 - Allow Bitbucket runner to access host's environmental variable

Our development team will give a first-hand update on that ticket if there's any progress made so I would suggest keeping a watch and vote for it.


Do note however that there's no ETA on enhancement request, and all enhancements are implemented with this policy in mind: Implementation of New Features Policy

Best Regards,
Atlassian Bitbucket Cloud Support

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

3,470 views 3 10
Read article

Atlassian Community Events