🎈 Welcome to the Marketplace — Explore and discover the ecosystem around DatoCMS, and share your own work with the community!

Travis CI

Trigger a build of your website on TravisCI directly from the DatoCMS UI, and get a notification of the status of the build when it completes

This guide assumes you have a working static website project on your machine integrated with DatoCMS. If that's not your case, you can return to the previous sections of this documentation to see how to properly configure the DatoCMS administrative area and how to integrate DatoCMS with your favorite static website generator.

Create your Git repository

Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.

Terminal window
$ git init
$ git add .

Commit the files that you've staged in your local repository.

Terminal window
$ git commit -m 'First commit'

At the top of your GitHub repository's Quick Setup page, click the clipboard icon to copy the remote repository URL. In Terminal, add the URL for the remote repository where your local repository will be pushed.

Terminal window
$ git remote add origin YOUR_GITHUB_REPOSITORY_URL

Now, it's time to push the changes in your local repository to GitHub.

Terminal window
git push -u origin master

Now that your project is up and running on GitHub, let's connect it to Travis.

Enable TravisCI

Sign in to Travis CI with your GitHub account, go to your profile page and activate Travis CI for the repository you want to build.

Add the DatoCMS API token as environment variable

Reach the TravisCI settings page of your project, and add an environment variable called DATO_API_TOKEN containing the read-only API token of your DatoCMS administrative area:

You can find the API token in the Admin area > API tokens section:

Configure .travis.yml

The next step is to add a .travis.yml file to your repository. Travis CI uses this file in the root of your repository to learn about your project and how you want your builds to be executed. How this file needs to be structured differs a lot depending on the static website generator you are using. Here we'll show you some examples to get started.

Please refer to the official TravisCI documentation to learn everything regarding how to configure your build and how to properly deploy the actual website to S3.

Jekyll

1
language: ruby
2
script:
3
# first dump all the remote content as local files
4
- bundle exec dato dump
5
# then generate the website
6
- bundle exec dato jekyll build
7
deploy:
8
provider: s3
9
access_key_id: XXX
10
secret_access_key: YYY
11
bucket: your-bucket
12
local_dir: public
13
skip_cleanup: true
14
acl: public_read

Hugo

1
language: node_js
2
sudo: required
3
before_script:
4
# download latest version of hugo
5
- wget https://github.com/spf13/hugo/releases/download/v0.19/hugo_0.19-64bit.deb
6
# install it
7
- sudo dpkg -i hugo*.deb
8
script:
9
# first dump all the remote content as local files
10
- ./node_modules/.bin/dato dump
11
# then generate the website
12
- hugo
13
deploy:
14
provider: s3
15
access_key_id: XXX
16
secret_access_key: YYY
17
bucket: your-bucket
18
local_dir: public
19
skip_cleanup: true
20
acl: public_read

Middleman

1
language: ruby
2
script:
3
- bundle exec middleman build
4
deploy:
5
provider: s3
6
access_key_id: XXX
7
secret_access_key: YYY
8
bucket: your-bucket
9
local_dir: build
10
skip_cleanup: true
11
acl: public_read

Metalsmith

1
language: node_js
2
script:
3
# first dump all the remote content as local files
4
- ./node_modules/.bin/dato dump
5
# then generate the website
6
- node index.js
7
deploy:
8
provider: s3
9
access_key_id: XXX
10
secret_access_key: YYY
11
bucket: your-bucket
12
local_dir: build
13
skip_cleanup: true
14
acl: public_read

Connect TravisCI to DatoCMS

There's only one last step needed: connecting DatoCMS to TravisCI, so that everytime one of your editors press the Publish changes button in your administrative area, a new build process (thus a new publication of the final website) gets triggered.

To do so, go to the Admin area > Environments, select TravisCI and follow the instructions to conclude the integration:

When everything is done, confirm the integration pressing the Save Settings button.

Subscribe to our newsletter! 📥
One update per month. All the latest news and sneak peeks directly in your inbox.
support@datocms.com ©2024 Dato srl, all rights reserved P.IVA 06969620480