GITLAB CI错误加载密钥"/dev/fd/63":格式无效错误:作业失败:退出代码1 [英] GITLAB CI Error loading key "/dev/fd/63": invalid format ERROR: Job failed: exit code 1

查看:193
本文介绍了GITLAB CI错误加载密钥"/dev/fd/63":格式无效错误:作业失败:退出代码1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码giltlab-ci.yml:

Here is my code giltlab-ci.yml :

 before_script:
  ##
  ## Install ssh-agent if not already installed, it is required by Docker.
  ## (change apt-get to yum if you use an RPM-based image)
  ##
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'

  ##
  ## Run ssh-agent (inside the build environment)
  ##
  - eval $(ssh-agent -s)
  ##
  ## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
  ## We're using tr to fix line endings which makes ed25519 keys work
  ## without extra base64 encoding.
  ## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
  ##
  - mkdir -p ~/.ssh
  #- echo -n "$PROJECT_SSH_KEY" | ssh-add - >/dev/null
  - echo "$PROJECT_SSH_KEY"
  - ssh-add <(echo "$PROJECT_SSH_KEY")
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
      ##
  ## Create the SSH directory and give it the right permissions
  ##
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh

  ##
  ## Optionally, if you will be using any Git commands, set the user name and
  ## and email.
  ##
  #- git config --global user.email "user@example.com"
  #- git config --global user.name "User name"

我把这个放了出去

使用gitlab-runner 11.8.0(4745a6f3)运行 在Allence-Tunisie-docker-runner sH47eTgb上 将Docker executor与image ntfactory/ci-tool:0.0.2一起使用... 拉码头工人图像ntfactory/ci-tool:0.0.2 ... 使用docker image sha256:7fe7b170806f6846271eec23b41c4f79202777f62c0d7a32165dc41722900979 对于ntfactory/ci-tool:0.0.2 ... 通过a732493b4b94在Runner-sH47eTgb-project-11060727-concurrent-0上运行... 克隆存储库... 克隆到'/builds/alence-tunisie/e-formation'... 检出0a6b48ef为feat/gitlab-ci ... 跳过Git子模块设置 正在检查缓存是否为默认值... 没有提供URL,将不会从共享缓存服务器下载缓存.取而代之的是将提取本地版本的缓存. 成功提取缓存 $其中的ssh-agent || (apt-get更新-y& apt-get安装openssh-client -y) /usr/bin/ssh-agent $ eval $(ssh-agent -s) 代理pid 12 $ mkdir -p〜/.ssh $ echo"$ SSH_PRIVATE_KEY" | tr -d'\ r'| ssh-add->/dev/null 加载密钥(stdin)"时出错:格式无效 错误:作业失败:退出代码1

Running with gitlab-runner 11.8.0 (4745a6f3) on Allence-Tunisie-docker-runner sH47eTgb Using Docker executor with image ntfactory/ci-tool:0.0.2 ... Pulling docker image ntfactory/ci-tool:0.0.2 ... Using docker image sha256:7fe7b170806f6846271eec23b41c4f79202777f62c0d7a32165dc41722900979 for ntfactory/ci-tool:0.0.2 ... Running on runner-sH47eTgb-project-11060727-concurrent-0 via a732493b4b94... Cloning repository... Cloning into '/builds/allence-tunisie/e-formation'... Checking out 0a6b48ef as feat/gitlab-ci... Skipping Git submodules setup Checking cache for default... No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. Successfully extracted cache $ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y ) /usr/bin/ssh-agent $ eval $(ssh-agent -s) Agent pid 12 $ mkdir -p ~/.ssh $ echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null Error loading key "(stdin)": invalid format ERROR: Job failed: exit code 1

即使我尝试过-回显"$ SSH_PRIVATE_KEY" | tr -d'\ r'| SSH添加 ->/dev/null我收到此错误

even though i tried - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null i get this error

加载密钥(stdin)"时出错:格式无效

Error loading key "(stdin)": invalid format

推荐答案

$ SSH_PRIVATE_KEY中的私钥格式错误时,会发生此错误,如果在其中添加一些随机字符,则可以轻松地在本地对其进行测试.特别是,当您复制&以在线形式将私钥粘贴到SSH_PRIVATE_KEY变量中.它与----- BEGIN RSA PRIVATE KEY -----,----- END RSA PRIVATE KEY -----块前后的换行符有关.因此,我使用base64编码来确保密钥的格式正确.

This error happens when the private key in $SSH_PRIVATE_KEY is malformed, you can easily test it locally if you add some random characters in it. In particular, it happens on Travis-CI when you just copy & paste the private key into the SSH_PRIVATE_KEY variable in the online form. It has to do with the new line characters after and before the -----BEGIN RSA PRIVATE KEY-----, -----END RSA PRIVATE KEY----- blocks. For this reason, I use base64 encoding to make sure the key is formatted properly.

尝试一下:

  • 对您的RSA私钥进行编码

  • Encode your private RSA key

cat my_private_key | base64 -w0

cat my_private_key | base64 -w0

将base64字符串添加到您的项目变量中.

Add the base64 string to your project variables.

ssh-add<(回显"$ SSH_PRIVATE_KEY" | base64 -d)

ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 -d)

https://gitlab.com/gitlab -examples/ssh-private-key/issues/1#note_15038961

这篇关于GITLAB CI错误加载密钥"/dev/fd/63":格式无效错误:作业失败:退出代码1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆