重现我的问题:
export PROJECT_NAME=hello export IMAGE_NAME=hello-world docker-compose -p ${PROJECT_NAME} up
version: '2' services: app: image: ${IMAGE_NAME}
我收到错误:
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.
我在我的mac机器上使用相同的代码创建了脚本并且它可以正常工作!
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.
我不明白为什么它不适用于詹金斯。 如您所见,docker-compose没有看到shell env变量:(
答案 0 :(得分:1)
看看拉吉夫的回应。 docker-compose, export environnement variables are not working in Jenkins
Rajiv回复的副本:
jenkins shell中的环境变量不会自动导入。通过Jenkins作业工作区下的.env文件添加环境变量。
$ echo PROJECT_NAME=hello >> .env
$ echo IMAGE_NAME=hello-world >> .env
$ cat .env
export PROJECT_NAME=hello
export IMAGE_NAME=hello-world
然后运行
$ docker-compose up