2

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?

2
  • That's probably not it but it's worth the shot, can you add a space before do in for i in "${!array[@]}"do Commented Jun 26, 2018 at 0:12
  • My error on the copy it has the space, still doesnt work D: Commented Jun 26, 2018 at 16:24

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

9 Comments

i am getting "This job is stuck, because you don't have any active runners that can run this job. " error on pipline page, how i can fix it
whats your configuration?
I am using gitlab with yml based deployment. pipeline is created properly but how i can execute pipeline to deploy on AWS EC2. I have setup above configuration in yml file but when i try to execute pipeline manually it's show above error. can you please let me know how i can setup runner for AWS EC2 and execute pipeline.
That problem if i remember is when you use "tags", need to change that if you got it
i have removed tags but problem is AWS EC2 work with pem file, so how i can register runner with pem file. can you please let me know how i can register runner on runner server using pem file, my runner server is independent server and my gitlab server is also indepemend server.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.