2
votes

we have a lumen application we move the project to GitLab we wanna pull the project if all is ok.

We add the two scripts:

.gitlab-ci.yml:

variables:
 - All or variables
stages:
  - test
  - production

testing:
  type: test
  image: php:7.1
  script:
    - echo "ok"

#Production stage
production:   
   stage: production   
   before_script: 
     - 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'   
   script:     
      - bash .gitlab-deploy.sh   
   environment:     
      name: production     
      url: https://alpha.merci.network/
   when: manual

our deploy script ".gitlab-deploy.sh" looks like:

#!/bin/bash

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

#Iterate servers for deploy and pull last commit
for i in "${!array[@]}"do    
      echo "Deploy project on server ${array[i]}"    
      ssh ubuntu@${array[i]} "cd /var/www && git pull origin master"
done

We already add the configuration:

enter image description here

When we push changes to the repo/master we saw on the dashboard log the next error:

enter image description here

So what we are missing? Any advice?

1
That's probably not it but it's worth the shot, can you add a space before do in for i in "${!array[@]}"do Naguib Ihab
My error on the copy it has the space, still doesnt work D:Ulises

1 Answers

2
votes

I just change the for to this for make it work:

for i in "${!array[@]}"; do
  echo "Deploying information to EC2 and Gitlab"
  echo "Deploy project on server ${array[i]}"
  ssh ubuntu@${array[i]} "cd  /var/www/merci_deploy_api && git pull origin master"
done