簡體   English   中英

在 GitLab CI 中添加 SSH 密鑰時出現語法錯誤

[英]Syntax error when adding SSH key in GitLab CI

參考: https : //gitlab.ida.liu.se/help/ci/ssh_keys/README.md

以下腳本有問題。 即使我將最后一個符號從 ` 更改為 ',問題是如何修復錯誤,如下所示

$ ssh-add <(echo "$SSH_PRIVATE_KEY") /bin/sh: eval: line 24: 語法錯誤:意外的 "("

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
  - '[[ -f /.dockerinit ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config`

我試了很多次,下面的.gitlab-ci.yml應該可以正常工作。

    image: gitlab/dind:latest

variables:
  COMPOSE: docker-compose

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'

stages:
  - build
  - test
  - deploy

# Add a job called 'build' -> to run your builds
# TODO: Build the image in remote docker registry 
build-dev:
  stage: build 
  script:
    - sh scripts/install-dev.sh
    - $COMPOSE build
  only:
    - dev 

build-master:
  stage: build 
  script:
    - sh scripts/install.sh
    - $COMPOSE build
  only:
    - master 

我也在這里打開了一個問題。

為了使它工作,我不得不更換:

ssh-add <(echo "$SSH_PRIVATE_KEY")

與:

printenv SSH_PRIVATE_KEY | ssh-add -

暫無
暫無

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

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