The problem when retrieving data when I try to perform an automatic deployment through gitlab

Viewed 203

I made a deploy script via ssh and gitlab but when the git pull script is executed, everything appears as already up to date and I can't even run the composer commands

before_script:
  - apt-get update -qq
  - apt-get install -qq git
  # Setup SSH deploy keys
  - 'which ssh-agent || ( apt-get install -qq openssh-client )'
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    
deploy_staging:
  type: deploy
  environment:
    name: staging
    url: test.ro
  script:
    - ssh -p 28785 test@test "git checkout development && git pull"
    - cd server
    - composer i
    - composer optimize
    - php artisan migrate
    - cd ..
    - cd client
    - npm i
    - npm run dev
    - exit
  only:
    - development
$ apt-get update -qq
$ apt-get install -qq git
$ which ssh-agent || ( apt-get install -qq openssh-client )
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 266
$ ssh-add <(echo "$SSH_PRIVATE_KEY")
Identity added: /dev/fd/63 (/dev/fd/63)
$ mkdir -p ~/.ssh
$ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ ssh -p 28785 
$ git pull
$ Already up to date

Don't I make the connection via ssh ok?

1 Answers

Try first to replace your ssh step with:

ssh -p 28785 test@test "id -a && ls -alrth && pwd && git status && git remote -v"

That way, you can make sure you are:

  • in the right path (which would be by default /home/test, an odd path for a Git view)
  • in an actual local Git repository, and the right branch (hence the git status)
  • referencing the right remote (meaning the remote repository where you have pushed new commits, which should be pulled)
Related