How to pass a lot of bamboo variables to a docker container?

Viewed 2546

I have the Docker configuration task and I need to execute in docker container a bash script which uses Bamboo variables.

Is there a way to pass all Bamboo variables to docker container?

I have lots of Bamboo plans with quite a few different variables in them so putting all variables in container environment variables is not an option.

Of course, I can dump them into file in one task and parse the variables from file in docker task, but I was hoping to find an easier solution.

Thanks!

3 Answers

You can use the env_file option using compose:

web:
  env_file:
    - your-variables.env

or use docker run --env-file=your-variables.env ....

The .env file is a simple key value text file:

# my env file
BAMBOO_ENV=development

What version of Bamboo are you using?

There are a problem with bamboo variables is docker containers in some versions of Bamboo, but was fixed in Bamboo 6.1.0:

Unable to use variables in Container name field in Run docker task

Workaround:

  • Create a Script Task that runs before the Docker Task.
  • Run commands like

    echo "export sourcepath=$ini_source_path" > scriptname.sh
    chmod +x scriptname.sh
    

The Docker Task will be map the ${bamboo.working.directory} to the Docker \data volume.

So the just created scriptname.sh script is available in the Docker container.The script will be executed, and will set the variable correctly.

More info in this post: How to send bamboo variables from Bamboo script to docker container?

Related