I created a new ssh key in my local machine, added the public key to my account settings ssh keys, and the private key to the ci/cd settings of the project.
My .gitlab-ci.yml looks like the following:
build app:
stage: build
only:
- feature/ci-cd-pipeline-v1
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $GIT_URL >> ~/.ssh/known_host
- git config user.email "[email protected]"
- git config user.name "CI"
- git remote add acquia $GIT_URL
script:
- echo "Script will runb"
- git checkout -b feature/ci-cd-pipeline-v1
- git push acquia feature/ci-cd-pipeline-v1
The goal of this is to push the updated code to my Acquia repository(which also has the ssh public key), but I get the following error when the pipeline runs:
$ command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )
$ eval $(ssh-agent -s)
Agent pid 12
$ echo "$SSH_PRIVATE_KEY" | ssh-add -
Error loading key "(stdin)": invalid format
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
I resolved this issue posted by regenerating an RSA key, then secondly, instead of:
I use
In summary, the format of the ssh key was incorrect.
It throws a different error now, but I guess this would form part of a different question.