# Continuous integration --- FOR NOOBS! ![](https://media.giphy.com/media/mVuHMzLyy0ef6/giphy.gif) --- ## Definition --- Development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is verified by an automated build, allowing teams to detect problems early. --- “Continuous Integration doesn’t get rid of bugs, but it does make them dramatically easier to find and remove.” — [Martin Fowler, Chief Scientist, ThoughtWorks](https://www.martinfowler.com/articles/continuousIntegration.html) --- ![](https://media.giphy.com/media/1xOQlQxrIX4Jw6lBZI/giphy.gif) --- ![](https://i.imgur.com/CaNWdSW.png) --- ## Why? --- * Nobody is working on a code base that deviates significantly from anyone else’s. * Team knows what the current state of the code truly is. * Avoid big risky merges. * People can refactor as much as they need to. --- By integrating regularly, you can **detect errors** quickly, and locate them more easily. Because you’re integrating so frequently, there is significantly **less back-tracking** to discover where things went wrong. 🎉 You can spend more time building features and not squashing bugs! 🎉 --- ![](https://media.giphy.com/media/oSUtmrhRz5te0/giphy.gif) --- ### Contrary to popular belief, continuous integration is an attitude, not a tool. It's a shared agreement by the team that: 1. When we get the latest code from the repository, it will always build successfully and pass all tests. 2. We will check in our code every two to four hours. --- #### Ways to make this happen: 1. Before check-in, run the build and tests and make sure they pass. 2. Tell people not to update from the repository because you're doing an integration. 3. Check in. --- 5. Go to a different machine (often a dedicated "integration machine"), get the latest code from the repository, and make sure latest changes build and pass there, too. 6. Done - tell people they can update again. --- ### Continuous integration is part of a bigger idea of continuous delivery: --- ![](https://i.imgur.com/wBlN6F7.png) --- ## How? ![](https://media.giphy.com/media/l4pT1eIWDh3pOnB3G/giphy.gif) P.S. It's got something to do with Trigger! --- 1. When you merge to master it will trigger the integration tests. 2. Execute a set of tests. 3. Declare that the code integrated successfully or not. 4. For compiled languages (C# or C++...), there are default tests included already. 5. For scripting languages (Python or Javascript) developers must create their own. --- ## Who is Travis? --- ![](https://media.giphy.com/media/xT1Ra40M1XG7BSjXBS/giphy.gif) --- ![](https://media.giphy.com/media/L7cVrIkAfdEhW/giphy.gif) --- ![](https://media.giphy.com/media/14lRMUFXsg3voc/giphy.gif) --- As a continuous integration platform, Travis CI supports: * your development process by automatically building and testing code changes * providing immediate feedback on the success of the change. Travis CI can also automate other parts of your development process by: * managing deployments * notifications --- ## What can Travis do? --- When you run a build, Travis CI do: * clones your GitHub repository into a brand-new virtual environment * carries out a series of tasks to build and test your code. ![](https://i.imgur.com/aVqQau4.png =50x50) **If one or more of those tasks fail, the build is considered broken!** If none of the tasks fail, the build is considered passed and Travis CI can deploy your code to a web server or application host. --- ![](https://i.imgur.com/Yq3C7O7.png) --- [Check out the DWYL guide for the easiest Travis Set-up](https://github.com/dwyl/learn-travis) --- ## Example 1. We created a repository. 2. Inside our repo, we created a server in our server.js file. 3. Linked Travis with Github. 4. Next, we created a .travis.yml file in our repo. 5. Inside the .travis.yml file, declare the lanuage you are using (node.js) --- ![](https://i.imgur.com/WjnwmIL.png) --- 6. Then create tests - scripting languages (Javascript) need to write their own. 7. Travis will automatically check if your tests are passing 8. If tests aren't passing, it won't merge! 9. This way you're stopped from deploying an app with failing tests. --- ![](https://i.imgur.com/ObiGUZa.png) --- ## Resources * [Defintion](https://www.thoughtworks.com/continuous-integration) * [Noobs Guide: Continuous Integration & Continuous Delivery](https://medium.com/@brenn.a.hill/noobs-guide-continuous-integration-continuous-delivery-continuous-deployment-d26ac4f2beeb) * [Introduction to Continuous Integration & Continuous Deployment](https://medium.com/pulseque/introduction-to-continuous-integration-continuous-deployment-38c3ebc07221) * [Continuous Integration - Martin Fowler](https://martinfowler.com/bliki/ContinuousIntegrationCertification.html) * [Travis (not the band)](https://travis-ci.org/) * [DWYL](https://github.com/dwyl/learn-travis) ---
{"metaMigratedAt":"2023-06-14T23:08:42.633Z","metaMigratedFrom":"Content","title":"Continuous integration","breaks":true,"contributors":"[{\"id\":\"1b68b571-5a4a-477d-b6b9-d88dc0089c18\",\"add\":2218,\"del\":128},{\"id\":\"c49e8a40-eed9-405a-9829-9349b5de5d8b\",\"add\":3656,\"del\":2656},{\"id\":\"2967aacf-1990-431e-b963-91e79ce4a2bf\",\"add\":1309,\"del\":92},{\"id\":\"4a393201-e032-4634-aabf-fb4f094fb8d4\",\"add\":778,\"del\":1}]"}
    206 views