docker-compose, export environnement variables are

2019-07-09 11:47发布

问题:

I have a docker-compose.yml file with differents variables

version: "2"
services:

  data:
    image: "${registryUrl}/data:${image_version}"

In my shell, I export registryUrl & image_version

export registryUrl=zhcjie.distribution.ata.com:8652
export image_version=1.0-SNAPSHOT
docker-compose up

that's work in my local (I'm using boot2Docker) but it doesn't work in Jenkins. I have a wrong message.

The registryUrl variable is not set. Defaulting to a blank string.
The image_version variable is not set. Defaulting to a blank string.

I try to pass env variable with EnvInject plugin, it doesn't work too.

回答1:

Your environment variables inside jenkins shell will not be imported automatically. Add environment variables through .env file under your Jenkins job's workspace.

$ cat .env registryUrl=zhcjie.distribution.ata.com:8652 image_version=1.0-SNAPSHOT

Then run

docker-compose up