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?
ssh-agent bashstarts a new shell, you shouldevalthe values being returned by it, or pass the identity file directly tossh -i