Reputation: 4133
To reproduce my issue:
export PROJECT_NAME=hello export IMAGE_NAME=hello-world docker-compose -p ${PROJECT_NAME} up
version: '2' services: app: image: ${IMAGE_NAME}
I get error:
Started by user anonymous
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/jobs/testenv/workspace
[workspace] $ /bin/sh -xe /tmp/hudson1988957642163027988.sh
+ PROJECT_NAME=hello
+ IMAGE_NAME=hello-world
+ docker-compose -p hello up
The IMAGE_NAME variable is not set. Defaulting to a blank string.
I created script with same code on my mac machine and it works!
Alexanders-Mini:deploy alexanderkondaurov$ ./test.sh
Creating hello_app_1
Attaching to hello_app_1
app_1 |
app_1 | Hello from Docker.
app_1 | This message shows that your installation appears to be working correctly.
I don't understand why it doesn't work in jenkins. As you see docker-compose doesn't see shell env variables :(
Upvotes: 1
Views: 1374
Reputation: 73
look at the response of Rajiv. docker-compose, export environnement variables are not working in Jenkins
Copy of the Rajiv response :
Your environment variables inside jenkins shell will not be imported automatically. Add environment variables through .env file under your Jenkins job's workspace.
$ echo PROJECT_NAME=hello >> .env
$ echo IMAGE_NAME=hello-world >> .env
$ cat .env
export PROJECT_NAME=hello
export IMAGE_NAME=hello-world
Then run
$ docker-compose up
Upvotes: 2