玖叶教程网

前端编程开发入门

GitLab CI/CD 前端项目(gitlab webide)

image: node:latest
 
stages:
  - install
  - test
  - build-dist
 
# 在流水线中使用package.json缓存node_modules,只要package.json内容没变就一直使用缓存
cache:
  key:
    files:
      - package.json
  paths:
    - node_modules
 
# 定义安装npm包的job
install:
  stage: install
  script:
    - npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
    - npm install --registry=http://registry.npm.taobao.org
 
# 定义代码验证的job
code-lint:
  stage: test
  script:
    - npm run lint
  allow_failure: true # 运行失败,代码验证失败后仍然会执行后续job
 
# 编译生成文件的job
build-dist:
  stage: build-dist
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
 
    - ssh-keyscan 115.159.52.223 >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
    - npm run build
    - scp -r dist [email protected]:/usr/local/www
  artifacts:
    paths:
      - dist
  only: # 只在master分支编译,为了能够
    - master

usr/local/www : 服务器nginx代理指向的目录

SSH_PRIVATE_KEY: 免密登录的私钥

使用公有runner


发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言