stages:
- build
- package
cache:
paths:
# maven下载三方依赖的缓存目录
- .m2/repository/
variables:
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
# 公司私有的镜像仓库账号
S_USERNAME: "xxx"
# 公司私有的镜像仓库密码
S_PASSWORD: "xxx"
# 要推送的整个镜像名和版本号
MY_IMAGE: "xxx.xxx.com:8081/xxx/xxx:1.0.0"
build-job:
stage: build
image: maven:3.6.3-jdk-8-openj9
script:
# MVN_SETTINGS_XML变量在GitLab的设置=>CI/CD=>变量中定义,值就是整个settings.xml的内容(文本),变量类型设置成了"文件"
- mvn package -s ${MVN_SETTINGS_XML} ${MAVEN_OPTS}
only:
# 只对master分支运行job
- master
timeout: 30 min
artifacts:
expire_in: 1 week
paths:
# 可以指定到某个文件(这里指定到了jar包),或者整个target/目录
- target/xxx.jar
package-job:
stage: package
image: docker:19.03.12-dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
services:
- name: docker:19.03.12-dind
command:
# 阿里的镜像仓库
- --registry-mirror=https://registry.cn-hangzhou.aliyuncs.com
# 公司私有的镜像仓库
- --insecure-registry=xxx.xxx.com:8081
only:
- master
timeout: 30 min
before_script:
#- mkdir -p $HOME/.docker
#- echo $DOCKER_AUTH_CONFIG > $HOME/.docker/config.json
- docker info
script:
- docker build . -t ${MY_IMAGE}
# 登录公司私有镜像仓库,也可以参考before_script,向.docker/config.json写入正确的token,就可以免除docker login这步
- docker login xxx.xxx.com:8081 -u ${S_USERNAME} -p ${S_PASSWORD}
- docker push ${MY_IMAGE}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)