gitlab的ci/cd发布项目隐藏帐号密码(1)
- UID
- 1066743
|
gitlab的ci/cd发布项目隐藏帐号密码(1)
gitlab设置帐号密码等变量
gitlab中配置变量名和值,点击settings,ci/cd,找到variables,填入key和value即可。
如果是很多个项目通用的变量,可以设置在group的变量中,在group层级找到settings即可。
如果是单个项目使用的变量,只在项目层级找到settings,设置项目的变量。
注意,protected如果打勾,则只有protected分支和打了tag的ci能够获取到这个变量。
gitlab的ci中获取gitlab中设置的变量如下:
variables:
AWS_ACCESS_KEY_ID: ${AWSAccessKeyID}
AWS_DEFAULT_REGION: ${DefaultRegionName}
AWS_SECRET_ACCESS_KEY: ${AWSSecretAccessKey}
或者docker build时传入环境变量
- docker build -t -e REDIS_HOST=${HOST} $IMAGE_NAME:sit .
完整参考如下:
variables:
MGAP_ENV: ci
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache"
IMAGE_NAME: 123-3456-1.amazonaws.com.cn/mgap-module/mgap-module
cache:
paths:
- .cache/pip
- .venv/
stages:
- test
- package
- build
- deploy
test:
stage: test
only:
- dev
- master
- tags
image: 567.aliyuncs.com/zzq-public/poetry:latest
script:
- python3.7 -m venv ./venv
- source venv/bin/activate
- poetry develop
- poetry run pytest -s -vv --cov=./mgap_module
package:
stage: package
only:
- dev
- master
- tags
image: 567.aliyuncs.com/zzq-public/poetry:latest
script:
- poetry build
artifacts:
paths:
- dist/*.whl
expire_in: 30 days
build-sit:
stage: build
only:
- dev
image: 567.aliyuncs.com/zzq-public/docker-with-awscli:latest
tags:
- common
script:
- docker build -t -e REDIS_HOST=${HOST} $IMAGE_NAME:sit .
- eval $(aws ecr get-login --no-include-email --region cn-northwest-1)
- docker push $IMAGE_NAME:sit
variables:
AWS_ACCESS_KEY_ID: ${AWSAccessKeyID}
AWS_DEFAULT_REGION: ${DefaultRegionName}
AWS_SECRET_ACCESS_KEY: ${AWSSecretAccessKey} |
|
|
|
|
|