Github Actions 工件构建不会成功复制

问题描述 投票:0回答:1

我正在尝试将我的工件复制到 /var/www/build 以便它由 nginx 提供服务。不幸的是,由于某些未知原因,它没有复制。

err: cp: cannot stat '/home/runner/work/investing/investing/client/build': No such file or directory

也许 cp 引用的是服务器而不是主机(运行者)?不确定,但 100% 的时间杀手。请解决。

name: CI/CD Pipeline

concurrency: production

on:
  push:
    branches: [main]

jobs:
  build-clientside:
    runs-on: ubuntu-latest
    steps:
      - name: Set CI environment variable to false
        run: echo "CI=false" >> $GITHUB_ENV

      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: "14.x"

      - name: Install clientside dependencies
        run: |
          cd $GITHUB_WORKSPACE/client
          npm ci

      - name: Build clientside
        run: |
          cd $GITHUB_WORKSPACE/client
          npm run build

      - name: Publish artifact
        uses: actions/upload-artifact@v2
        with:
          name: client-build
          path: ${{ github.workspace }}/client/build/
          if-no-files-found: error

  deploy:
    needs: build-clientside
    runs-on: ubuntu-latest
    steps:
      - name: Download build artifact
        id: download
        uses: actions/download-artifact@v2
        with:
          name: client-build
          path: ${{ github.workspace }}/client/build/

      - name: 'Echo download path'
        run:  | 
            echo ${{steps.download.outputs.download-path}}
            cd ${{steps.download.outputs.download-path}}
            chmod u+rx ${{steps.download.outputs.download-path}}
            ls -la

      - name: Deployment
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.DROPLET_URL }}
          key: ${{ secrets.DROPLET_PEM_KEY }}
          username: root
          script: |
            rm -rf /var/www/build
            cp -R ${{steps.download.outputs.download-path}} /var/www/
            systemctl reload nginx 
            cd /root/investing 
            git reset --hard 
            git checkout main 
            git pull 
            docker-compose down --rmi local 
            docker-compose pull 
            docker-compose up -d
github-actions cp github-actions-artifacts
1个回答
0
投票

err: cp: cannot stat '/home/runner/work/investing/investing/client/build': 没有这样的文件或目录

您正在通过 SSH 进行复制。你需要使用 SCP。

https://github.com/appleboy/scp-action.

一旦您通过 SSH 连接到远程服务器,该路径即

${{steps.download.outputs.download-path}}
将变得无效,因为那里没有预设任何工件。在运行 SSH 脚本之前,您需要先对其进行 SCP。

© www.soinside.com 2019 - 2024. All rights reserved.