Back to blogs
How to Implement Automatization Deployment Gitlab to Pantheon
Submitted on: May 8 2024
To start creating an automatization between Gitlab and Pantheon we need to following some steps.
Create a file and script to make the magic and pushing everything to Pantheon from Gitlab.
Basic Script:
stages: - deploy before_script: # See https://docs.gitlab.com/ee/ci/ssh_keys/README.html - eval $(ssh-agent -s) - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null - mkdir -p $HOME/.ssh && echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config" - git config --global user.email "$GITLAB_USER_EMAIL" - git config --global user.name "Gitlab CI" deploy:dev: stage: deploy environment: name: dev url: https://dev-$PANTHEON_SITE.pantheonsite.io/ script: - git config checkout.defaultRemote origin - git remote add pantheon $PANTHEON_GIT_URL - git fetch pantheon - git branch -v - git checkout master - git push pantheon master --force only: - master
Gitlab by default use "
.gitlab-ci.yml
" as a name for the file- Get this code and create a new file with the name
.gitlab-ci.yml
in your project root. - Commit and push this file to the repository project in Gitlab on the master branch.
- Once you have this file in the Gitlab repository, let's configure some variables used on the script. For example
$PANTHEON_GIT_URL
and$PANTHEON_SITE
- To configure these variables we need to go to Gitlab Project page then in the left sidebar menu there is the a
Settings
option. Click on this menu item and then click onCI/CD
submenu item. - Then go to that page and go to the
Variables
section - Now create the variables that you used on the script. In this case we used
$PANTHEON_GIT_URL
and$PANTHEON_SITE
so now we need to set a value for them. - For
$PANTHEON_GIT_URL.
Go to Pantheon and copy the git url and page on value field. - For
$PANTHEON_SITE
it is the name of the site. - Click on update variable and then we can start to pushing things automatically on pantheon.
- Check in the left sidebar the CI/CD menu item all deployments and check the jobs.