gitlab-cicd

一 首先需要制作镜像



本地打包好 上传到镜像仓库

docker buildx build --platform linux/amd64 -t hub.ucloudadmin.com/uphost-sre/centos7-cicd:v0.1.1 .
docker push hub.ucloudadmin.com/uphost-sre/alpline-cicd:v0.1.5

二 pipline文件


image: hub.ucloudadmin.com/uphost-sre/alpline-cicd:v0.1.5
stages:
- build
- deploy
 
build-file:
  stage: build
  script:
    - export ROOT_PATH=$(pwd)
    - echo $CI_COMMIT_SHA && echo $ROOT_PATH && echo $ID_RSA
    - cd $ROOT_PATH/windows
    - if [ -f hybrid_cloud.7z ];then rm -f hybrid_cloud.7z;fi
    - 7za a -t7z -r hybrid_cloud.7z steps2/ steps3/
    - curl --upload-file hybrid_cloud.7z http://172.18.183.45:62121/files/hybrid_cloud.7z-$CI_COMMIT_SHA
    - cd $ROOT_PATH/linux
    - if [ -f hybrid_cloud.tar ];then rm -f hybrid_cloud.tar;fi
    - tar -cvf hybrid_cloud.tar *
    - curl --upload-file hybrid_cloud.tar http://172.18.183.45:62121/files/hybrid_cloud.tar-$CI_COMMIT_SHA
  artifacts:
    expire_in: '3 days'
    when: on_success
  tags:
    - uaek-c1
  only:
    - master
 
.deploy:
  before_script:
    - if [ ! -d ~/.ssh ];then mkdir ~/.ssh;fi
    - if [[ $ID_RSA ]];then echo "$ID_RSA" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa; fi
  allow_failure: false
  tags:
    - uaek-c1
 
deploy--cn-wlcb-01:
  extends: .deploy
  stage: deploy
  script:
    - curl -o hybrid_cloud.7z http://172.18.183.45:62121/hybrid_cloud.7z-$CI_COMMIT_SHA
    - curl -o hybrid_cloud.tar http://172.18.183.45:62121/hybrid_cloud.tar-$CI_COMMIT_SHA
    - scp -o "StrictHostKeyChecking no" hybrid_cloud.7z [email protected]:/home/
    - scp -o "StrictHostKeyChecking no" hybrid_cloud.tar [email protected]:/home/
  when: manual
  only:
    - master
  allow_failure: true

你可能感兴趣的:(gitlab-cicd)