Deploy to a Linux Virtual Machine

VSTS | TFS 2018

We'll show you how to set up continuous deployment of your app to an nginx web server running on Ubuntu using Visual Studio Team Services (VSTS) or Team Foundation Server (TFS) 2018. You can use the steps in this quickstart for any app as long as your continuous integration process 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 process

You'll need a continuous integration (CI) build process 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 process, 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 VSTS make it easier to organize the servers you want to use to host your app. A deployment group is a collection of machines with a VSTS agent on each of them. Each machine interacts with VSTS 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 VSTS web portal https://{your-account}.visualstudio.com, navigate to the Build & Release hub, 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.

    Creating a Linux deployment group

    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 VSTS Agent. Type "q" to exit the file editor and return to the shell prompt.

  11. Back in VSTS or TFS, on the Deployment groups page of the Build & Release hub in VSTS, open the myNginx deployment group. On the Targets tab, verify that your VM is listed.

    Verifying the Linux deployment group

Define your CD release process

Your CD release process 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 definition:

    • 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 definition that's automatically linked to the build definition.

      Creating a new release definition from the build summary

    • Open the Releases tab of the Build & Release hub, open the + drop-down in the list of release definitions, and choose Create release definition.

      Creating a new release definition in the Releases page

  2. Choose Start with an Empty process.

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

    Checking or selecting the build definition 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 definition from the Releases tab.

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

    Removing the Agent phase

  6. Choose ... next to the Environment 1 deployment process and select Add deployment group phase.

    Adding a Deployment group phase

  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 phase will run on each of the machines in the deployment group you specified.

  8. Choose + next to the Deployment group phase 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 definition.

    Saving the release definition

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 definition with the artifacts produced by a specific build. This will result in deploying the build.

  1. Choose + Release and select Create Release.

  2. Check that the build you just completed is selected and choose Create.

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

  4. Open the Logs tab to watch the release console output.

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

Next steps