我遵循GitLab文档以使我的项目的CI能够克隆其他私有依赖项。一旦它开始工作,我就从.gitlab-ci.yml中提取
before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'转到单独的shell脚本setup.sh中,如下所示:
which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
eval $(ssh-agent -s)
ssh-add <(echo "$SSH_PRIVATE_KEY")
mkdir -p ~/.ssh
[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config只离开:
before_script:
- chmod 700 ./setup.sh
- ./setup.sh然后我开始:
Cloning into '/root/Repositories/DependentProject'...
Warning: Permanently added 'gitlab.com,52.167.219.168' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.如何在提取的脚本中复制原始行为?
发布于 2017-09-04 16:55:23
当运行ssh-添加或者使用源或者。因此,脚本在同一个shell中运行,在您的示例中是:
before_script:
  - chmod 700 ./setup.sh 
  - . ./setup.sh或
before_script:
  - chmod 700 ./setup.sh 
  - source ./setup.sh要更好地解释为什么需要在与其他的shell相同的shell中运行,请查看相关问题这里的答案。
https://stackoverflow.com/questions/46030051
复制相似问题