gitlab CI/CD 配置

2023-05-25  本文已影响0人  索哥来了

前提:根据同事已经配置好的 .gitlab-ci.yml 文件,查看其参数的意义以及如何让一个新的项目能自动构建。

stages:
  - build
  - deploy
variables:
  GIT_CLEAN_FLAGS: -ffdx -e node_modules/

build:
  stage: build
  cache:
    key: buildres
    paths:
      - dist
    policy: push # 在作业完成时上传缓存,但在作业开始时从不下载缓存
  tags:
    - ams_ci
  only:
    - master
  script:
    - npm install
    - npm run build
deploy:
  stage: deploy
  cache:
    key: buildres
    paths:
      - dist
    policy: pull # 仅在作业开始时下载缓存,但在作业完成时从不上传更改
  tags:
    - ams_ci
  only:
    - master
  script:
    - sshpass -p $password scp -r ./dist/* rss@119.23.**.**:/home/rss/www_ams # 将dist目录里的文件推到服务器119.23.**.**:/home/rss/www_ams 目录下,其中 password 在gitlab上配置,如图:
image.png

文档地址:https://docs.gitlab.cn/jh/ci/,参数都能看到,需要注意GIT_CLEAN_FLAGS:

着重注意下 tags,需要注册runner
windows安装:https://docs.gitlab.cn/runner/install/windows.html

实际操作如图:

注册runner:https://docs.gitlab.cn/runner/register/

实际操作如图:

成功后,在gitlab上可以看到:

测试:(本人注释了deploy,测试build阶段,并将master分支改为aaa分支)
第一次报错,如图:

原因:

按照要求修改后,最后成功:

上一篇下一篇

猜你喜欢

热点阅读