1

I am working with CI, CD but unfortunately I messed up with shell scripting. On my gitlab-ci.yml file I called a bashscript at the time on deploy. But unfortunately whenever I want to pull using the command the response is failed. For this bash script my response is

#!/bin/bash

# Get server list 
set -f
string=$DEPLOY_SERVER_IP
array=(${string//,/ })

# Iterate servers for deploy and pull last commit 
for i in "${!array[@]}"; do
  echo "Deploy project on server ${array[i]}"
  ssh bitnami@${array[i]} " ssh-agent bash && ssh-add keys/relation-fe && cd htdocs/relation-fe/ && git pull origin master "
done

my response is something like this

Executing "step_script" stage of the job script
$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 21206
$ mkdir -p ~/.ssh
$ echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
$ chmod 600 ~/.ssh/id_rsa
$ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ bash .gitlab-deploy-prod.sh
Deploy project on server 1.2.3.4
Could not open a connection to your authentication agent.
Cleaning up file based variables
ERROR: Job failed: exit status 1

SO how could I solve the error? the error shows that gitlab was successful to access my server but at the time of running the ssh-agent and adding the keys by ssh-key the script cannot execute the commands. Well error comes from here. I'm confused with the bash script and shell script thing. So I cannot figure out the error from my script. I was able to create a file on my git push but I cannot pull things after authenticating with the ssh-key can any one help me with this?

9
  • 1
    ssh-agent bash starts a new shell, you should eval the values being returned by it, or pass the identity file directly to ssh -i
    – Panki
    Mar 29 at 12:40
  • See this post for more info
    – Panki
    Mar 29 at 12:40
  • Thank you for the response. But could you please give me an accurate answer by modifying the code? Mar 29 at 12:41
  • Sorry, I got my own work to do :/
    – Panki
    Mar 29 at 12:48
  • Thanks for the help Mar 29 at 12:48
0

It looks like Gitlab is not connecting to your runner, which is different than your server. Make sure that your runner is available and gitlab can connect to it.

1
  • Thank you for the comment, but there are several ways to do CI and CD. The way you told is to run the gitlab runner on my server so that the runner could trigger the pull request. Well I'm going for a different approach. btw thanks for the comment Mar 29 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.