我已经在gitlab CI中定义了我的管道,如下所示:
dev-build:
stage: build
variables:
VERSION: "dev"
BASE_URL: "dev.example.com"
script:
- docker build --build-arg VERSION=${VERSION} --build-arg BASE_URL=${BASE_URL} -t example:${VERSION} .
- docker push example:${VERSION}
only:
- dev
dev-deploy:
stage: deploy
variables:
VERSION: "dev"
script:
- ssh root@myserver.co, "docker rm -f example_beta; docker pull example:${VERSION} && docker run -d --name example_beta --publish 7733:80 example:beta"
only:
- dev
如何只定义一次环境变量,而不在每个作业中重新定义它们?
答案 0 :(得分:1)
在每个阶段之外使用变量:
variables:
DEV_VERSION: "dev"
dev-build:
blahblah
dev-deploy:
blahblah