首页 > 其他分享 > GitLab CICD Day 17 - Image递增版本号 - 2

GitLab CICD Day 17 - Image递增版本号 - 2

时间:2023-02-11 20:33:15浏览次数:45  
标签:17 版本号 CICD image Version build docker hellocat Image

  1. 新增build版本号

variables:
user: eric
pwd: Admin@1234
harbor: http://172.16.128.215:8080
image_hellocat: 172.16.128.215:8080/hive/hellocat


stages:
- testing
- build

image: denoland/deno


testing:
stage: testing
tags:
- shell
script:
- echo "testing..."

build_image:
stage: build
tags:
- shell
before_script:
- export Image_Version=$(cat deno.json | jq -r .version)
- echo $Image_Version
script:
- docker login -u $user -p $pwd $harbor
- docker build -t $image_hellocat:$Image_Version-build$CI_PIPELINE_IID . # 增加build小版本号(CI_PIPELINE_IID)默认全局变量
- docker push $image_hellocat:$Image_Version-build$CI_PIPELINE_IID

  1. 上传结果:

        GitLab CICD Day 17 - Image递增版本号 - 2_Image



  • ​示例2:修改为Latest镜像
variables:
user: eric
pwd: Admin@1234
harbor: http://172.16.128.215:8080
image_hellocat: 172.16.128.215:8080/hive/hellocat


stages:
- testing
- build

image: denoland/deno


testing:
stage: testing
tags:
- shell
script:
- echo "testing...."

build_image:
stage: build
tags:
- shell
before_script:
- export Image_Version=$(cat deno.json | jq -r .version)
- echo $Image_Version
script:
- docker login -u $user -p $pwd $harbor
- docker build -t $image_hellocat:$Image_Version-build$CI_PIPELINE_IID . #打包镜像,镜像名为:helloat:1.0.1-build-187
- docker push $image_hellocat:$Image_Version-build$CI_PIPELINE_IID #上传当前镜像


- docker tag $image_hellocat:$Image_Version-build$CI_PIPELINE_IID $image_hellocat:latest #把当前的镜像,修改为latest
- docker push $image_hellocat:latest #上传latest镜像




运行结果:

        GitLab CICD Day 17 - Image递增版本号 - 2_docker_02

标签:17,版本号,CICD,image,Version,build,docker,hellocat,Image
From: https://blog.51cto.com/u_12391275/6050946

相关文章