Gitlab SSH示例不适用于docker:git/dind映像

Gitlab SSH示例不适用于docker:git/dind映像,gitlab,Gitlab,我正在阅读文档: 我正在使用当前的gitlab-ci.yml: image: docker:git services: - docker:dind stages: - node_test - docker_one variables: DOCKER_DRIVER: overlay before_script: # Install ssh-agent if not already installed, it is required by Docker. # (change apt-ge

我正在阅读文档:

我正在使用当前的gitlab-ci.yml:

image: docker:git
services:
- docker:dind
stages:
- node_test
- docker_one
variables:
  DOCKER_DRIVER: overlay
before_script:
  # Install ssh-agent if not already installed, it is required by Docker.
  # (change apt-get to yum if you use a CentOS-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
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  # For Docker builds disable host key checking. Be aware that by adding that
  # you are suspectible to man-in-the-middle attacks.
  # WARNING: Use this only with the Docker executor, if you use it with shell
  # you will overwrite your user's SSH config.
  - mkdir -p ~/.ssh
  - ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts
  - ssh-keyscan gitlab.com | sort -u - ~/.ssh/known_hosts -o ~/.ssh/known_hosts
  - '[[ -f /.dockerinit ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
node_test:
  image: node:7.3.0
  stage: node_test
  script:
    - ls
docker_one:
  stage: docker_one
  script:
    - docker info
image:docker:git
服务:
-码头工人:丁
阶段:
-节点检验
-码头工人一号
变量:
DOCKER_驱动程序:覆盖
在脚本之前:
#安装ssh代理如果尚未安装,Docker需要它。
#(如果使用基于CentOS的映像,请更改为转到yum)
-'哪个ssh代理| |(apt get update-y&&apt get install openssh client-y)'
#运行ssh代理(在生成环境中)
-eval$(ssh代理-s)
#将SSH_PRIVATE_key变量中存储的SSH密钥添加到代理存储
-ssh add~/.ssh/config'
节点测试:
图像:节点:7.3.0
阶段:节点测试
脚本:
-ls
docker_one:
舞台:docker_one
脚本:
-码头工人信息
节点测试通过:

Running with gitlab-ci-multi-runner 1.10.4 (b32125f)
Using Docker executor with image node:7.3.0 ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Waiting for services to be up and running...
Pulling docker image node:7.3.0 ...
Running on runner-4e4528ca-project-2641294-concurrent-0 via runner-4e4528ca-machine-1487244621-a8ff6b11-digital-ocean-4gb...
Cloning repository...
Cloning into '/builds/instanty/test'...
Checking out 0b261283 as master...
Skipping Git submodules setup
Identity added: /dev/fd/63 (rsa w/o comment)
$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 11
$ ssh-add <(echo "$SSH_PRIVATE_KEY")
$ mkdir -p ~/.ssh
$ ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
$ ssh-keyscan gitlab.com | sort -u - ~/.ssh/known_hosts -o ~/.ssh/known_hosts
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
$ [[ -f /.dockerinit ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ ls
Build succeeded
使用gitlab ci multi runner 1.10.4(b32125f)运行
正在将Docker executor与映像节点一起使用:7.3.0。。。
正在启动服务docker:dind。。。
正在拖动docker图像docker:dind。。。
正在等待服务启动并运行。。。
正在拖动docker图像节点:7.3.0。。。
通过runner-4e4528ca-machine-1487244621-a8ff6b11-digital-ocean-4gb在runner-4e4528ca-project-2641294-concurrent-0上运行。。。
正在克隆存储库。。。
正在克隆到“/builds/instanty/test”。。。
正在以主服务器身份签出0b261283。。。
正在跳过Git子模块安装程序
添加标识:/dev/fd/63(rsa,无注释)
$which ssh agent | |(apt get update-y&&apt get install openssh client-y)
/usr/bin/ssh代理
$eval$(ssh代理-s)
代理pid 11
$ssh add>~/.ssh/已知\u主机
#gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
#gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
#gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
$ssh keyscan gitlab.com | sort-u-~/.ssh/known_hosts-o~/.ssh/known_hosts
#gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
#gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
#gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
$[-f/.dockerinit]]&&echo-e“主机*\n\tStritThostKeyChecking否\n\n”>~/.ssh/config
$ls
建造成功
当我使用镜像docker:git和服务dind:

Running with gitlab-ci-multi-runner 1.10.4 (b32125f)
Using Docker executor with image docker:git ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Waiting for services to be up and running...
Pulling docker image docker:git ...
Running on runner-4e4528ca-project-2641294-concurrent-0 via runner-4e4528ca-machine-1487244733-2b616928-digital-ocean-4gb...
Cloning repository...
Cloning into '/builds/instanty/test'...
Checking out 0b261283 as master...
Skipping Git submodules setup
$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 14
$ ssh-add <(echo "$SSH_PRIVATE_KEY")
/bin/sh: eval: line 50: syntax error: unexpected "("
ERROR: Build failed: exit code 2
使用gitlab ci multi runner 1.10.4(b32125f)运行
正在将Docker executor与图像Docker:git一起使用。。。
正在启动服务docker:dind。。。
正在拖动docker图像docker:dind。。。
正在等待服务启动并运行。。。
正在提取docker图像docker:git。。。
通过runner-4e4528ca-machine-1487244733-2b616928-digital-ocean-4gb在runner-4e4528ca-project-2641294-concurrent-0上运行。。。
正在克隆存储库。。。
正在克隆到“/builds/instanty/test”。。。
正在以主服务器身份签出0b261283。。。
正在跳过Git子模块安装程序
$which ssh agent | |(apt get update-y&&apt get install openssh client-y)
/usr/bin/ssh代理
$eval$(ssh代理-s)
代理pid 14

$ssh add映像使用的shell无法识别您使用的语法:
ssh添加ssh.priv
ssh add ssh.priv