首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GitLab管道:在YML中工作,在提取的SH中失败

GitLab管道:在YML中工作,在提取的SH中失败
EN

Stack Overflow用户
提问于 2017-09-04 03:52:04
回答 1查看 152关注 0票数 0

我遵循GitLab文档以使我的项目的CI能够克隆其他私有依赖项。一旦它开始工作,我就从.gitlab-ci.yml中提取

代码语言:javascript
运行
复制
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中,如下所示:

代码语言:javascript
运行
复制
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

只离开:

代码语言:javascript
运行
复制
before_script:
- chmod 700 ./setup.sh
- ./setup.sh

然后我开始:

代码语言:javascript
运行
复制
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.

如何在提取的脚本中复制原始行为?

EN

Stack Overflow用户

回答已采纳

发布于 2017-09-04 16:55:23

当运行ssh-添加或者使用源或者。因此,脚本在同一个shell中运行,在您的示例中是:

代码语言:javascript
运行
复制
before_script:
  - chmod 700 ./setup.sh 
  - . ./setup.sh

代码语言:javascript
运行
复制
before_script:
  - chmod 700 ./setup.sh 
  - source ./setup.sh

要更好地解释为什么需要在与其他的shell相同的shell中运行,请查看相关问题这里的答案。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46030051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档