From your question here, I think that getting your dependencies through http is not possible, so here's what you need to do in order to use scp
:
- Generate a key pair
- Copy the private key to a gitlab CI variable (let's call it
SSH_PRIVATE_KEY
)
- Copy the public key to the server gitlab will connect to and add it to your
~/.ssh/authorized_keys
file
- Tell your CI pipeline to use the private key that is stored in the Gitlab CI variable
In order to do that last step, just add the following to your .gitlab-ci.yml
in the script or before_script section of the job of interest:
- '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'
You may also want to specify that CodeA is dependent on B and C. In order for that to work, build_CodeB and build_CodeC need to be in a different stage than build_CodeA.
Besides that, you need a way to carry the built files from build_CodeB and build_CodeC jobs to the build_CodeA job. One way to do that is to use artifacts.
In the end, your .gitlab-ci.yml
file should look something like this:
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
I only put the SSH key setup part in build_CodeC because that's where you are using scp
. You would need to copy this over to any job that would require to use scp
. I'm thinking you may need to do this in build_codeB since your tar file will not be carried to the build_CodeB job.