kind: pipeline
type: docker
name: build
trigger:
  event: [ push ]
  branch: [ master ]
volumes:
  - name: node_modules
    host:
      # 宿主机的绝对路径
      path: /tmp/drone/cache/node_modules
steps:
  - name: build-project
    image: node:16.15.1
    volumes:
      - name: node_modules
        path: /drone/src/node_modules
    commands:
      - pwd
      - ls -alt
      - npm config set registry https://registry.npm.taobao.org # 切换淘宝镜像
      - npm install
      - npm run build
    when:
      event: push
  - name: deploy-project
    image: appleboy/drone-scp
    settings:
      host: ssh_ip
      username: root
      password:
        from_secret: ssh_password
      port: 22
      target: /www/wwwroot/admin.gwkjxb.com  #宿主机绝对路径
      source: ./dist/*
      script:
        - rm -rf /www/wwwroot/admin.gwkjxb.com/dist/
    when:
      event: push
  - name: notify
    pull: if-not-exists
    image: guoxudongdocker/drone-dingtalk:latest
    settings:
      token: 9ad4ebd689e7833204dddfbc67435bc4fe82ab934614ea63a9b9fe4b6e206576
      type: markdown
      message_color: true
      message_pic: true
      sha_link: true
    when:
      status: [ failure, success ]
