我们正在尝试使用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。酒吧,,echo root:cat ~/.ssh/temp.pub
>~/. ssh/temp-formated。酒吧,,Chmod 700/home/runner/.ssh/temp- formatting .pub
当我们尝试运行以下命令时,会得到错误响应scp -o StrictHostKeyChecking=no -i/home/runner/。ssh/temp/code-web/目标/代码。战争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 }}
下面是错误日志。
我们已经在同一个仓库的其他构建中为其他构建尝试了多个构建-这些构建也失败了我们已经证实这个秘密还在活动。构建也是成功的因此文件"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/runnern', 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.rnPermission denied, please try again.rnPermission denied, please try again.rnroot@<ip>: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).rnlost connectionn")
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
我在使用ubuntu-latest作为yml文件中的作业运行程序时也遇到了类似的问题。代替ubuntu-latest我使用ubuntu-20.04那问题就解决了。
您可以在您的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
它适合我。