CI/CD Fails at the Test phase

I’m pretty new to CI/CD so I have most likely made an obvious error in my set up but the first test always fails.

TEST: gitlab will ssh to the Jetson NX and will build the software on native environment. If successful, we will go to the next stage.

I have put the.gitlab-ci.yml below and an image of the error.

In CI/CD variables, I have put my jetsons ssh port number, IP and the SSH key that I generated on the device.

image

.gitlab-ci.yml
variables:
IMAGE_NAME: alexvizgard/vizgard_app
IMAGE_TAG: JP46.Im0020.V0010
DOCKERFILE: dockerfile_build_vizgard_app
IMAGE_NAME2: vizgard_app
IMAGE_TAG2: latest
IMAGE_NAME3: alexvizgard/ai_server_app
IMAGE_TAG3: JP46.Im0020.V0010

stages:

  • test
  • build
  • deploy

run_test:
stage: test
before_script:
- chmod 400 $SSH_KEY
script:
- ssh -o StrictHostKeyChecking=no -i ${SSH_KEY} ${SSH_USERNAME}@${SSH_ADDRESS} -p ${SSH_PORT} “cd /home/aiserver/Software/test_vizgard/build && rm -rf CMakeCache.txt && /home/aiserver/.local/bin/cmake -DNATIVE=ON … && make -j$(nproc)”

It looks like the $SSH_KEY variable holds the contents of a SSH key. The chmod command expects the path to the SSH key file.

Suggestion: write the content to a file, and reference that instead. E.g.:

 before_script:
- mkdir -p /some/path/.ssh && chmod 600 /some/path/.ssh
- echo $SSH_KEY > /some/path/.ssh/id
- chmod 400 /some/path/.ssh/id
script:
- ssh -o StrictHostKeyChecking=no -i /some/path/.ssh/id ${SSH_USERNAME}@${SSH_ADDRESS} -p ${SSH_PORT} “cd /home/aiserver/Software/test_vizgard/build && rm -rf CMakeCache.txt && /home/aiserver/.local/bin/cmake -DNATIVE=ON … && make -j$(nproc)”

@thiagocsf thank you very much for your feedback. It seems to have got further in the process but its failing. I’ve spent a lot of time messing round with SSH keys to try and get things working but with little success. can you assist?

run_test:
stage: test
before_script:
- mkdir -p /home/aiserver/.ssh && chmod 600 /home/aiserver/.ssh
- echo $SSH_KEY > /home/aiserver/.ssh/id
- chmod 400 /home/aiserver/.ssh/id

script:
- ssh -o StrictHostKeyChecking=no -i /home/aiserver/.ssh/id ${SSH_USERNAME}@${SSH_ADDRESS} -p ${SSH_PORT} “cd /home/aiserver/Software/test_vizgard/build && rm -rf CMakeCache.txt && /home/aiserver/.local/bin/cmake -DNATIVE=ON … && make -j$(nproc)”

Hi, @Alexvizgard.

From a CI configuration perspective, there’s nothing wrong with your setup.

I believe the problem you’re having is due to the contents of $SSH_KEY. You can’t post it here since it’s a private key, so I won’t be able to tell whether or not it’s a valid SSH key.

My suggestion is to set this variable on your local dev environment with the same value you’ve set in GitLab, and try to run the same command from your CI script. Make sure that there’s no ssh agent configured, as this may give you false results.

The error you’re seeing is from the ssh client, so you should be able to debug this locally before using it in CI. To make it closer to CI, you could try the above in a container, using the same image your CI job uses (e.g. docker run -it --rm <image> sh). This also eliminates the ssh agent interference as it won’t be running in the newly created container.

Your original screenshot had an error with '-----BEGIN', which tells me you’re likely using the right key but there could be a formatting issue with the variable. If your project is private, you can cat the contents of the file before calling ssh so you can see in the CI log if the file contains a valid key in the right format.

edit: I forgot to mention. You might be able to simplify your script a bit by defining SSH_KEY as a file type variable. With this type of variable, GitLab will save the value of the variable (i.e. the ssh key) in a temporary file, and set the variable value as the path to the file. So in the script above you wouldn’t need the mkdir and echo steps (you might still need the chmod - I’m not sure which permissions the temp file is created with, and the ssh client is particular about it).

Good luck!