This is an interesting problem that I just solved yesterday- creating a CNAME file from a Travis CI server.
My finished site that was built and published from Travis CI server was giving me a 404 page.
Well, when I went into the settings for the Github repository and added my custom domain name everything worked!
However, I'm trying to set up continuous deployment with Travis CI where the CI server runs the deployment script to host the files. So, I needed an automated way to create this CNAME file.
Luckily, there's many simple ways of creating a file with some text in BASH. The one that I ended up incorporating makes use of the echo command. The contents of the file is just a string being echoes, and we then redirect that result (using the > symbol) into a file named CNAME. The final code would look like this:
Here is an example of a Travis.yml file. It first installs the environment, npm, and all that stuff. Then we run the unit tests (gulp test) and build the project (gulp build). If those finish successfully then it will run the deploy.sh file.
The code below is the full deploy.sh script. In the very first line we can see the new echo command that creates the CNAME. Then we simply push the files over to where our public project is being hosted (in this case gh-pages branch on Github).
The posts on this site are written and maintained by Jim Lynch. About Jim...