- 新增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
- 上传结果:
- 示例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镜像
运行结果: