getting started with Travis CI and continous integration
posted on April 4, 2020


Author: Luran Manfio

Travis CI is a tool used for continuous integration(CI) which is commonly known as the process of merger of developer code often and against known tests. This prevents the problem with developer code that causes errors or problems with the master code. This is more important when working on code collaboratively to prevent code from changing “underneath” your code(when base code changes that you were not editing or relying on). Travis CI will run the code on each commit and test the code against known tests to verify the commits and mergers. This creates an easy method for finding the problem when the code Inevitably breaks.


title: Geeting started and set up description: setting up your travis CI —

The process of adding Travis to your git repositories is straight forward. You’ll first need to create a .travis.yml file within your repository which will be the configuration file for Travis. You’ll then create an account on Travis website that will be linked to your GitHub. Once you’ve done this you can access your repositories on the Travis website. Find the repository that you added the .travis.yml file under the repository tab on the Travis website. You’ll then turn Travis on by flicking the switch beside your repository. You can confirm that you did the process right by going to your setting on the GitHub repository and checking the webhooks. There you should see a hyperlink to the Travis website.

Once you’ve made the connection you’ll need to now configure the .travis.yml file to preform the automated testing and deployment. To do this you’ll need to know some syntax for travis, the first being the Language setting which specifies the language the code is being constructed on. An example is using travis to test python code:

language: python

Next you’ll need to specify the version or versions of that language that you want to run. The syntax is depended on the language that your writing in so following the example it would be:

`language: python`
`Python:`
`- “3.5”`

You can also specify multiple versions by adding consecutive – “version ”. Following this you’ll have the freedom from choosing from several hooks to test the build of the code. These hooks are you specifying when in the code you want Travis to be preforming any tests. These hooks are:

`before_install:`
`install:`
`before_script:`
`script:`
`after_success:`
`after_failure:`
`after_script:`
`before_deploy:`
`deploy:`
`after_deploy:`

You DO NOT need to use or declare all of these hook. You can declare the hooks that are relevant to you and your code. One of the most commonly used hooks are the install,script,after success/failure, deploy. An example of before_install would be adding packages to allow for your code to run properly:

`language: python`
`python:`
`- “3.5”`
`before_install:`
`- “pandas==0.25.3”`

The script hook is where you’ll be telling the code to run/build. This could be calling the code on the repository with the required inputs. Deploy is used if you’d like Travis to deploy the script. If this is something you’ll want you can read more about it in the deployment documentation.

Now that you have a completed .travis.yml file you can commit it to your repository and Travis should run the file on your commit. You can check this on the Travis website along with the build log for your code. Now you can prevent entering merger hell and save yourself hours of decoding!

```