簡體   English   中英

Github 操作:因“失去連接”而失敗

[英]Github Action : failed with "lost connection"

我們正在嘗試使用 GitHub 操作構建模板化的 gcp 實例。

我們嘗試構建我們的 java 檔案並將其從 GitHub Ubuntu 機器傳輸到 GCP 實例。

我們已將 sshkey 設置為使用 ssh-keygen -t rsa -f ~/.ssh/temp -C root -q -N "" && chmod 400 ~/.ssh/temp && chmod 400 ~/ 從 Ubuntu 機器訪問 GCP 實例.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 日開始出現錯誤。

我們曾經遇到過一些失敗,但當我們重新運行構建時,同樣的工作正常。

構建.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 }}

以下是錯誤日志。

我們已經為同一存儲庫中其他構建中的其他構建嘗試了多個構建——那些也失敗了我們已經確認這個秘密仍然有效。 並且構建也成功因此文件“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

它對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM