从你的问题来看here https://stackoverflow.com/questions/43595993/approach-for-using-gitlab-ci-for-complex-builds,我认为通过 http 获取依赖项是不可能的,所以这是您需要执行的操作才能使用scp
:
- 生成密钥对
- 复制privategitlab CI 变量的键(我们称之为
SSH_PRIVATE_KEY
)
- 复制publicgitlab 将连接到的服务器的密钥并将其添加到您的
~/.ssh/authorized_keys
file
- 告诉您的 CI 管道使用存储在 Gitlab CI 变量中的私钥
为了完成最后一步,只需将以下内容添加到您的.gitlab-ci.yml
在感兴趣的作业的 script 或 before_script 部分:
- '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")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
您可能还想指定 CodeA 依赖于 B 和 C。为了使其正常工作,build_CodeB 和 build_CodeC 需要处于与 build_CodeA 不同的阶段。
除此之外,您还需要一种方法将构建的文件从 build_CodeB 和 build_CodeC 作业传送到 build_CodeA 作业。一种方法是使用文物 https://docs.gitlab.com/ce/ci/yaml/README.html#artifacts.
最后,你的.gitlab-ci.yml
文件应该看起来像这样:
image: ubuntu:12.04
stages:
- deps
- build
build_CodeC:
stage: deps
allow_failure: true
script:
- '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")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- scp user@remoteServer:/home/user/file.tar .
- sh ./continuous_integration/build_CodeC_dependency.sh
artifacts:
paths:
- path_to_built_codeC
build_CodeB:
stage: deps
script:
- sh ./continuous_integration/build_CodeB_dependency.sh
artifacts:
paths:
- path_to_built_codeB
build_CodeA:
stage: build
dependencies:
- build_CodeB
- build_CodeC
script:
- sh ./continuous_integration/build_CodeA.sh
我只将 SSH 密钥设置部分放在 build_CodeC 中,因为这就是您使用的地方scp
。您需要将其复制到任何需要使用的作业scp
。我认为您可能需要在 build_codeB 中执行此操作,因为您的 tar 文件不会被传送到 build_CodeB 作业。