Triggering GitLab-CI with Seams-CMS

banner

If you use a static site generator like Jekyll or Gatsby with GitLab-CI, you might want to trigger site generation each time your content changes. You could do this by triggering your CI manually, or uploading a git commit so your pipeline will trigger, but you can also let this trigger by Seams-CMS itself. Here's how.

Create a pipeline trigger

The first thing we need to do is create a pipeline trigger at Gitlab. Go to your GitLab project and click "Settings | CI/CD" in the menu.

Settings menu

Click on pipeline triggers. Here we are going to create a new trigger that we will be using later on.

Pipeline button

Add a description for your new trigger and click Add Trigger.

Pipeline button

Now you will receive a token for this trigger. This is the token that we will be using to generate our webhook. (The token stays visible at GitLab, so you can always take a look in case you lose the token).

Trigger token.

Create the webhook in Seams-CMS

Next, we leave GitLab and go to our workspace in Seams-CMS. Log into your account, select the workspace and click on webhooks in the development section (note that you need admin or developer permissions to add webhooks).

Workspace overview

Here we can add a new webhook. Click on Add new webhook. Now we need to add a description for this webhook. We also must select when this webhook should trigger. Select the checkbox next to "Content Entries". This will select all content entries so every time some entry changes, it will automatically trigger this webhook.

Finally, we need to add the actual webhook URL. This can be found at the GitLab page, but it should be:

 https://gitlab.com/api/v4/projects/PROJECT_ID/ref/REF_NAME/trigger/pipeline?token=TOKEN

Note that you have to fill in 3 types of info: the PROJECT_ID which is the id of the project. You can find that in your GitLab project on the main page (next below the title).

Secondly, we need REF_NAME. This is the branch or tag which will be triggered by this webhook. We use the REF_NAME master as this webhook should trigger the master branch of our GitLab project. Finally, there is the TOKEN, which is the token we found earlier on GitLab. Edit webhook

Once filled, we can click Save webhook and we will have the webhook pop up on the webhook page. When clicking to the details page of the webhook, you can manually trigger the webhook to see if it functions. After a few seconds, it should display an even in the events section of the webhook (click on the refresh button if nothing appears).

Webhook overview

This should trigger a new CI build at GitLab. You can verify this at GitLab itself:

CI triggered

Congratulations. Every time your content changes, it will automatically update your static site! (or anything else you like to trigger).