{"id":2159,"date":"2015-09-30T03:00:00","date_gmt":"2015-09-30T10:00:00","guid":{"rendered":"https:\/\/www.microsoft.com\/reallifecode\/index.php\/2015\/09\/30\/using-travis-ci-to-deploy-to-azure\/"},"modified":"2020-03-18T15:41:03","modified_gmt":"2020-03-18T22:41:03","slug":"using-travis-ci-to-deploy-to-azure","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/ise\/using-travis-ci-to-deploy-to-azure\/","title":{"rendered":"Using Travis CI to Deploy to Azure"},"content":{"rendered":"<p>Travis CI is known as everyone\u2019s favorite Continuous Integration system, offering free testing for open source projects. It also integrates seamlessly with GitHub, automatically testing all your branches, but also optionally pull requests. All around, it\u2019s an amazing tool to test and build applications written in a variety of languages, including Ruby, Node, Objective-C, Go, Java, and virtually everything else that runs on Linux &#8211; <a href=\"http:\/\/docs.travis-ci.com\/user\/languages\/csharp\/\">thanks to Mono, even C# and F# are supported<\/a>!<\/p>\n<p>It also features its own deployment engine, allowing developers to have Travis deploy successfully tested apps. We extended the Travis deployment engine with a provider for Azure Web Apps, enabling you to use your free GitHub account and your free Travis CI testing to deploy apps to your free Azure Web App. In this post, I\u2019ll explain how to use Travis to test your projects &#8211; and how you can deploy successfully tested apps directly to Azure.<\/p>\n<h2 id=\"requirements-github-travis-azure\">Requirements: GitHub, Travis, Azure<\/h2>\n<p>In order to use the full integration flow, you\u2019ll need an account with all three providers. Feel free to skip this part if you already have GitHub, Travis, and Azure setup.<\/p>\n<p>All three providers offer paid solutions, but for the basic flow, you won\u2019t have to pay a single penny: GitHub is free for any public source code; Travis will test your public GitHub repositories for free; and <a href=\"https:\/\/azure.microsoft.com\/en-us\/pricing\/details\/app-service\/\">Azure will gladly host simple web apps for free<\/a>.<\/p>\n<p>First, log into the Azure Management Portal and create a new Azure Web App. When creating the app, enable \u201cdeployment from source control\u201d, choosing \u201cLocal Git Repository\u201d as your deployment method. Azure will create a hosted Git repository for your website, meaning that we can <code class=\"highlighter-rouge\">git push<\/code> to Azure. Azure\u2019s deployment engine will carefully look at every single commit made, trying to understand what kind of application you have in your repository &#8211; and host your application using the appropriate services. If your repository contains a Node.js application, it will automatically install all dependencies and fire up a Node server. Similar logic exists for Python, PHP, ASP.NET, and Java.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2020\/03\/2015-09-30-travis-azure-webappgit.png\" alt=\"Creating a Web App in Azure\" \/><\/p>\n<p>If you never used Azure\u2019s continuous integration features, it is possible that you also don\u2019t have \u201cdeployment credentials\u201d setup. Those are the credentials used to authenticate with FTP or Git on Azure &#8211; for security reasons, you have to create a separate set of credentials and cannot use the username\/password combination used to login into the Azure Management Portal. To set your deployment credentials, select \u201cDeployment Credentials\u201d in your Web App\u2019s settings.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2020\/03\/2015-09-30-travis-azure-webappdplcredentials.png\" alt=\"Setting Deployment Credentials\" \/><\/p>\n<p>Then, create a GitHub repository and connect it to Travis. If this is your first time using Travis, check out their \u201c<a href=\"http:\/\/docs.travis-ci.com\/user\/getting-started\/\">Getting Started Guide<\/a>\u201d &#8211; it is quite good and should contain all the information you need.<\/p>\n<h2 id=\"add-deployment-instructions\">Add Deployment Instructions<\/h2>\n<p>Like all Travis settings, you configure your Azure deployment in <code class=\"highlighter-rouge\">.travis.yml<\/code>.<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>deploy:\r\n  provider: azure_web_apps\r\n  username: \"Your Azure Deployment Username\"\r\n  password: \"Your Azure Deployment Password\"\r\n  site: \"Name of your Azure Web App\"\r\n<\/code><\/pre>\n<\/div>\n<p>It\u2019d be unwise though to keep your deployment credentials in <code class=\"highlighter-rouge\">.travis.yml<\/code> &#8211; for that reason, the Azure provider also accepts environment variables. You can set secret environment variables in the Travis Settings for your repository. Use <code class=\"highlighter-rouge\">AZURE_WA_USERNAME<\/code> for the deployment username, <code class=\"highlighter-rouge\">AZURE_WA_PASSWORD<\/code> for the deployment password, and <code class=\"highlighter-rouge\">AZURE_WA_SITE<\/code> for the site name. Alternatively, <img decoding=\"async\" src=\"http:\/\/docs.travis-ci.com\/user\/encryption-keys\/\" alt=\"you can also encrypt your keys\" \/>.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2020\/03\/2015-09-30-travis-azure-traviscredentials.png\" alt=\"Travis Secrets\" \/><\/p>\n<p>Then, simply include these innocent two lines in your <code class=\"highlighter-rouge\">.travis.yml<\/code>:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>deploy:\r\n  provider: azure_web_apps\r\n<\/code><\/pre>\n<\/div>\n<h4 id=\"pre-deploy-steps\">Pre-Deploy Steps<\/h4>\n<p>You might want to customize your deployment &#8211; maybe you don\u2019t want to deploy the \u201cfresh\u201d GitHub repository, but instead have Travis push the content folder with all files generated during testing. This would allow you to use Travis for more than just testing &#8211; since the machine is already running, you can execute commands and scripts on your repository before it is being deployed to Azure. To enable this feature, use the <code class=\"highlighter-rouge\">skip_cleanup<\/code> setting:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>deploy:\r\n provider: azure_web_apps\r\n skip_cleanup: true\r\n<\/code><\/pre>\n<\/div>\n<h4 id=\"conditional-deployments\">Conditional Deployments<\/h4>\n<p>In most cases, deployments shouldn\u2019t happen for every single test run &#8211; you most likely want to limit the deployment to a specific branch, tag, or even language runtime. Travis offers settings that make this easily possible. All of the options below can be combined.<\/p>\n<p>To deploy only when a certain environment variable is present, use:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>deploy:\r\n provider: azure_web_apps\r\n on:\r\n   condition: $MY_ENV = super_awesome\r\n<\/code><\/pre>\n<\/div>\n<p>To deploy a certain branch only, use:<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>deploy:\r\n provider: azure_web_apps\r\n on:\r\n   branch: release\r\n<\/code><\/pre>\n<\/div>\n<p>Travis users often use multiple runtime versions in their tests. Let\u2019s take Node apps as an example: You\u2019ll probably test your app against Node 0.10, 0.12, and iojs, but you only want to deploy your application once. You can limit the deployment to only act when certain runtime versions are present. This works for <code class=\"highlighter-rouge\">jdk<\/code>, <code class=\"highlighter-rouge\">node<\/code>, <code class=\"highlighter-rouge\">perl<\/code>, <code class=\"highlighter-rouge\">php<\/code>, <code class=\"highlighter-rouge\">python<\/code>, <code class=\"highlighter-rouge\">ruby<\/code>, <code class=\"highlighter-rouge\">scala<\/code>, and <code class=\"highlighter-rouge\">go<\/code>.<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code>deploy:\r\n provider: azure_web_apps\r\n on:\r\n   node: '0.11' # this should be quoted; otherwise, 0.10 would not work\r\n<\/code><\/pre>\n<\/div>\n<p>Now, whenever you push a new commit to GitHub, Travis will test it &#8211; and if the test passes, it will deploy it over to Azure. Enjoy your continuous integration!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Travis CI is one of the best tools for testing, building, and deploying apps. Learn how to deploy apps to Azure Web Apps!<\/p>\n","protected":false},"author":21345,"featured_media":12788,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[10,16],"tags":[60,97,187,362],"class_list":["post-2159","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-app-services","category-devops","tag-azure","tag-azure-web-apps","tag-github","tag-travis-ci"],"acf":[],"blog_post_summary":"<p>Travis CI is one of the best tools for testing, building, and deploying apps. Learn how to deploy apps to Azure Web Apps!<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/2159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/users\/21345"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/comments?post=2159"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/2159\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/media\/12788"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/media?parent=2159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/categories?post=2159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/tags?post=2159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}