Skip to content

Instantly share code, notes, and snippets.

@Mattchewone Mattchewone/.gitlab-ci.yml Secret
Last active Jun 11, 2019

Embed
What would you like to do?
SSH deploy via Gitlab
image: node:latest
stages:
- deploy
deploy_staging:
type: deploy
before_script:
- apt-get update -qq
- apt-get install -qq git
# Setup SSH deploy keys
- 'which ssh-agent || ( apt-get -qq install openssh-client )'
- eval $(ssh-agent -s)
- echo "$SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
## Keyscan to add public keys to known_hosts
- ssh-keyscan example.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
environment:
name: staging
url: example.com
script:
- ssh root@example.com "cd var/www/ && git checkout master && git pull origin master && exit"
only:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.