2

我正在使用circleci 2.0,我试图让circleci通过ssh进入一个gcp实例并使用这个命令启动一个部署脚本

sudo /opt/google-cloud-sdk/bin/gcloud compute ssh instance-1 
--command=/home/deploy_staging.sh --zone=us-east1-b

从我的本地机器上执行此操作很好,但是当我尝试从 circleci 执行此操作时,我收到此错误:

WARNING: The public SSH key file for gcloud does not exist.
WARNING: The private SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Too long with no output (exceeded 10m0s)

显然这是 ssh 的问题。我读了一些关于将 ssh 密钥放在 gcp 实例中的内容,并且我已经将本地机器的 ssh 密钥放在那里,但这仍然不起作用。

4

2 回答 2

1

根据官方 CircleCI 文档,您首先需要在 CircleCI 应用程序中添加服务器的 SSH 密钥 - 这可以在您的项目设置和 SSH 权限部分下完成。

于 2019-02-27T14:49:19.580 回答
1
gcloud \
  --quiet \
  --project="${PROJECT}" \
  compute ssh "${INSTANCE_NAME}" \
  --zone "${ZONE}" \
  --strict-host-key-checking=no \
  --command "echo works"

--quiet就是你所需要的,如果一个密钥不可用,它会生成一个密钥。我将其与服务帐户一起使用。

WARNING: The public SSH key file for gcloud does not exist.
WARNING: The private SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Your identification has been saved in /root/.ssh/google_compute_engine.
Your public key has been saved in /root/.ssh/google_compute_engine.pub.
The key fingerprint is:
SHA256:un2aZmExTGVD0KvebEVqAujrlXoAb0u7jO3Z5boCWaA root@581dc589b7fa
The key's randomart image is:
+---[RSA 2048]----+
|        .==      |
|  .     ....     |
| . . . o   .     |
|E . o . + . .    |
|   *   .S+ o     |
|  o *  o= o .    |
|   + =+o.* .     |
|   +==.=+.=      |
|  .oO+===+       |
+----[SHA256]-----+
WARNING: Using OS Login user [sa_102839341411404994442] instead of default user [root]
于 2019-04-24T15:51:19.083 回答