Github 操作 : failed with "lost connection"

标签 github google-cloud-platform github-actions cicd

我们正在尝试使用 GitHub Actions 构建模板化的 gcp 实例。

我们尝试构建 Java 文件并将其从 GitHub Ubuntu 计算机传输到 GCP 实例。

我们已将 sshkey 设置为使用以下命令从 Ubuntu 计算机访问 GCP 实例 ssh-keygen -t rsa -f ~/.ssh/temp -C root -q -N ""&& chmod 400 ~/.ssh/temp && chmod 400 ~/.ssh/temp.pub && echo root: cat ~/.ssh/temp.pub > ~/.ssh/temp-formated.pub && chmod 700/home/runner/.ssh/temp-formated.pub

当我们尝试运行以下命令时,我们收到错误响应 scp -o StrictHostKeyChecking=no -i/home/runner/.ssh/temp ./code-web/target/code.war root@:/opt/code.war

该脚本在 2022 年 12 月 5 日之前运行良好,并从 2022 年 12 月 6 日开始出现错误。

我们曾经遇到过一些失败,但当我们重新运行构建时,同样的工作正常。

build.yml

# This is a basic workflow to help you get started with Actions

name: build-web

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the develop branch
 
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
    inputs:
      short_sha:
        description: 'Git sha on which build will be created'     
        required: true
        default: ''

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.short_sha }}
     
     # Build using mvn
      - name: Set up JDK 8
        uses: actions/setup-java@v2
        with:
          java-version: '8'
          distribution: 'adopt'
          cache: 'maven'
      - name: Build with Maven
        run: mvn --batch-mode --update-snapshots verify

      - name: Set up Cloud SDK
        uses: google-github-actions/setup-gcloud@v0
        with:
          service_account_key: ${{ secrets.GCP_SA_KEY }}
          export_default_credentials: true

      - name: Gcloud Version
        run: gcloud --version

      - name: Run build script
        run: python ./.github/workflows/build.py ${{ github.event.inputs.short_sha }}

以下是错误日志。

我们已经尝试了同一存储库中其他构建中的多个构建 - 这些也失败了 我们已经确认该 secret 仍然有效。 并且构建也成功,因此文件“code.war”存在

任何关于如何找出根本原因的想法或任何面临类似问题的人

###Running: ssh-keygen -t  rsa  -f ~/.ssh/temp -C root -q -N "" && chmod 400 ~/.ssh/temp && chmod 400 ~/.ssh/temp.pub && echo root:`cat ~/.ssh/temp.pub` > ~/.ssh/temp-formated.pub && chmod 700 /home/runner/.ssh/temp-formated.pub
###Exit Code: 0
###RESPONSE:(b'', b'')
####################################
#########Transfer public key to instance############
###Running: cd ~/ && pwd
###Exit Code: 0
###RESPONSE:(b'/home/runner\n', b'')
###Running: gcloud compute instances add-metadata dummy-temp-web --project=projectname --zone=us-east1-b --metadata-from-file ssh-keys=/home/runner/.ssh/temp-formated.pub
###Exit Code: 0
###RESPONSE:(b'', b'Updated [https://www.googleapis.com/compute/v1/projects/projectname/zones/us-east1-b/instances/dummy-temp-web].\n')
####################################
#Give time for key to propogate
#########copy to remote############
###Running: scp -o StrictHostKeyChecking=no -i /home/runner/.ssh/temp ./code-web/target/code.war root@<ip>:/opt/code.war
###Exit Code: 1
###RESPONSE:(b'', b"Warning: Permanently added '<ip>' (ECDSA) to the list of known hosts.\r\nPermission denied, please try again.\r\nPermission denied, please try again.\r\nroot@<ip>: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\nlost connection\n")
Traceback (most recent call last):
  File "/home/runner/work/code/code/./.github/workflows/gcloudBuild.py", line 100, in <module>
    execute(f'***copyBuldFileToRemoteCMD***', False)
  File "/home/runner/work/code/code/./.github/workflows/gcloudBuild.py", line [30](https://github.com/company/code/actions/runs/3628509641/jobs/6119611343#step:7:31), in execute
    raise Exception(f'Sorry, bad exit code***process.returncode***')
Exception: Sorry, bad exit code1

最佳答案

当我在 yml 文件中使用 ubuntu-latest 作为作业运行程序时,我也遇到了类似的问题。 我使用了 ubuntu-20.04 而不是 ubuntu-latest,然后问题就解决了。

你可以在你的 yml 文件中尝试这个

jobs:
# This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-20.04

它对我有用。

关于Github 操作 : failed with "lost connection",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74703085/

相关文章:

Git pull 请求说 "This branch has conflicts that must be resolved"

google-cloud-platform - 批量更新一百万行

replace - GITHUB ACTIONS 替换字符串中的字符

Github Action 无法评论 PR

github Diff 截断错误

linux - 无法将现有的 git 存储库推送到 github

git 无法将我的更新推送到远程

python - 使用 cURL 或 Python 使 Google Cloud Text to Speech 正常工作

node.js - 使用 Google 云服务帐户 key 文件中的内容设置 Heroku Config Var

github-actions - GitHub 操作 : env: Use pre-defined environment variables on RHS within env section