I was tasked with connecting our GitLab repos to the Pantheon repos, and I came across this article: How to connect GitLab and Pantheon to streamline Drupal and WordPress workflows. Definitely a great how-to! I had to do a bit of reworking ’cause both GitLab and Pantheon have made some updates in the four years since this article was written… but I finally got it working! 🎉
Here are some of the adjustments I had to make:
- This may seem rather small, but it tripped me up – GitLab’s default branch is now called
master, so when I pushed the Pantheon dev code to my GitLab repo, it added a new branch. For consistency’s sake, I changed the
masterbranch to my default branch.
- In the
before_script, before you can can run the
gitcommands, you need to install them. I also received an error that the permissions for my
SSH_PRIVATE_KEYwere too open, so I needed to change the permissions. Changed the permissions on the
$HOME/.sshdirectory, as well. Here’s where I landed for my full
- 'which ssh-agent || ( apk update && apk add openssh )'
- apk update && apk add git
- eval $(ssh-agent -s)
- mkdir -p $HOME/.ssh && echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config"
- chmod 700 $HOME/.ssh
- chmod 600 $SSH_PRIVATE_KEY
- ssh-add $SSH_PRIVATE_KEY
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "Gitlab CI"
- NOTE: GitLab variables default to Protected, and protected variables only work on protected branches and jobs, so for them to work with the
deploy:multidevjob, you can either disable the Protected flag on the variable or add a “protected” tag to the job. I legit spent 4+ hours hitting my head against the wall because of this!
- When the runner starts the build, the latest commit detaches from
HEAD, so you need to go back to your
masterbranch before you can push to the
masterdev branch on Pantheon. The script now looks like this:
- git checkout master
- git remote add pantheon $PANTHEON_GIT_URL
- git push pantheon master --force
- Ran into a similar issue on
deploy:multidev; I found out the hard way that too many commits creates a shallow branch, and Pantheon doesn’t permit pushing from a shallow branch. Needed to add
git fetch --unshallowin the
multidev-deploy.shfile before checking out my merge request source branch.
- Last but not least, I updated the
Dockerfileto have the latest version of composer and require the latest version of terminus, so it looks like this:
# Use the official Composer image as a parent image
# Update/upgrade apk
RUN apk update
RUN apk upgrade
# Make the Terminus directory
RUN mkdir -p /usr/local/share/terminus
# Install Terminus 3.x with Composer
RUN /usr/bin/env COMPOSER_BIN_DIR=/usr/local/bin composer -n --working-dir=/usr/local/share/terminus require pantheon-systems/terminus:"^3"
Hope I could help a few folks! 😊