Deploy to a Linux Virtual Machine

Azure Pipelines | TFS 2018

Note

Build and release pipelines are called definitions in TFS 2018 and in older versions. Service connections are called service endpoints in TFS 2018 and in older versions.

We'll show you how to set up continuous deployment of your app to an nginx web server running on Ubuntu using Azure Pipelines or Team Foundation Server (TFS) 2018. You can use the steps in this quickstart for any app as long as your continuous integration pipeline publishes a web deployment package.

A typical release pipeline for web applications

After you commit and push a code change, it is automatically built and then deployed. The results will automatically show up on your site.

Define your CI build pipeline

You'll need a continuous integration (CI) build pipeline that publishes your web application, as well as a deployment script that can be run locally on the Ubuntu server. To set up a CI build pipeline, see:

Make sure you follow the additional steps in that topic for creating a build to deploy to Linux.

Prerequisites

You'll need a Linux VM with Nginx web server to deploy the app. The deployment scripts used in the sample repositories have been tested on Ubuntu 16.04, and we recommend you use the same version of Linux VM for this quickstart. If you don't already have a Linux VM with Nginx, create one now in Azure using the steps in this example.

Create a deployment group

Deployment groups in Azure Pipelines make it easier to organize the servers you want to use to host your app. A deployment group is a collection of machines with an Azure Pipelines agent on each of them. Each machine interacts with Azure Pipelines to coordinate deployment of your app.

  1. Open a SSH session to your Linux VM. You can do this using the Cloud Shell button on the menu in the upper-right of the Azure portal.

    Azure portal cloud shell button

  2. Initiate the session by typing the following command, substituting the IP address of your VM:

    ssh <publicIpAddress>

    For more information, see SSH into your VM.

  3. Run the following command:

    sudo apt-get install -y libunwind8 libcurl3

    The libraries this command installs are pre-requisites for installing the build and release agent onto a Ubuntu 16.04 VM. Pre-requisites for other versions of Linux can be found here.

  4. Open the Azure Pipelines web portal, navigate to Azure Pipelines, and choose Deployment groups.

  5. Choose Add Deployment group (or New if you have existing deployment groups).

  6. Enter a name for the group such as myNginx and choose Create.

  7. In the Register machine section, make sure that Ubuntu 16.04+ is selected and that Use a personal access token in the script for authentication is also checked. Choose Copy script to clipboard.

    The script you've copied to your clipboard will download and configure an agent on the VM so that it can receive new web deployment packages and apply them to web server.

  8. Back in the SSH session to your VM, paste and run the script.

  9. When you're prompted to configure tags for the agent, press Enter (you don't need any tags).

  10. Wait for the script to finish and display the message Started Azure Pipelines Agent. Type "q" to exit the file editor and return to the shell prompt.

  11. Back in Azure Pipelines or TFS, on the Deployment groups page, open the myNginx deployment group. On the Targets tab, verify that your VM is listed.

Define your CD release pipeline

Your CD release pipeline picks up the artifacts published by your CI build and then deploys them to your nginx servers.

  1. Do one of the following to start creating a release pipeline:

    • If you've just completed a CI build then, in the build's Summary tab under Deployments, choose Create release followed by Yes. This starts a new release pipeline that's automatically linked to the build pipeline.

      Creating a new release pipeline from the build summary

    • Open the Releases tab of Azure Pipelines, open the + drop-down in the list of release pipelines, and choose Create release pipeline.

      Creating a new release pipeline in the Releases page

  2. Choose Start with an Empty job.

  3. If you created your new release pipeline from a build summary, check that the build pipeline and artifact is shown in the Artifacts section on the Pipeline tab. If you created a new release pipeline from the Releases tab, choose the + Add link and select your build artifact.

    Checking or selecting the build pipeline and artifact

  4. Choose the Continuous deployment icon in the Artifacts section, check that the continuous deployment trigger is enabled, and add a filter that includes the master branch.

    Checking or setting the Continuous deployment trigger

    Continuous deployment is not enabled by default when you create a new release pipeline from the Releases tab.

  5. Open the Tasks tab, select the Agent job, and choose Remove to remove this job.

    Removing the Agent job

  6. Choose ... next to the Stage 1 deployment pipeline and select Add deployment group job.

    Adding a Deployment group job

  7. For the Deployment Group, select the deployment group you created earlier such as myNginx.

    Selecting the deployment group

    The tasks you add to this job will run on each of the machines in the deployment group you specified.

  8. Choose + next to the Deployment group job and, in the task catalog, search for and add a Shell Script task.

    Adding a Shell Script task

  9. In the properties of the Shell Script task, use the Browse button for the Script Path to select the path to the deploy.sh script in the build artifact. For example, when you use the nodejs-sample repository to build your app, the location of the script is
    $(System.DefaultWorkingDirectory)/nodejs-sample/drop/deploy/deploy.sh

    Configuring the Shell Script task

  10. Save the release pipeline.

    Saving the release pipeline

Create a release to deploy your app

You're now ready to create a release, which means to start the process of running the release pipeline with the artifacts produced by a specific build. This will result in deploying the build.

  1. Choose + Release and select Create a release.

  2. In the Create a new release panel, check that the artifact version you want to use is selected and choose Create.

  3. Choose the release link in the information bar message. For example: "Release Release-1 has been created".

  4. In the pipeline view, choose the status link in the stages of the pipeline to see the logs and agent output.

  5. After the release is complete, navigate to your app and verify its contents.

Next steps