Azure Pipelines Installation

This guide will explain how to deploy from scratch a web App with the Hdiv Agent using Azure pipelines.

Setting up an App Service

If you already have an App service for deploying, you can use that one instead of creating a new one, so you can just go to section "Setting up a project".

Both Linux and Windows based App Services are supported.

1) Log in into https://portal.azure.com/ and click on the icon "App Services".

Usage

2) Click on "Add".

Usage

3) Set the proper values for your service. When finished, click "Create".

Usage

Usage

4) Your service will be deployed

Usage

Setting up a project

Some steps can be skipped if you already have an Azure project and repository containing your Web App code. If you already have one, you can jump to step 5)

1) Login into https://dev.azure.com/

2) Click the "New project button"

Usage

3) Add a project name and description.

4) Go to the "Repos" section of the project to get the options available to add some code. In this page, you can import an existing repository or use the provided options to create a new one.

Usage

5) If you do not have a .yml file for deploying your App with Azure Pipelines, you need to add one into your repository. You can use this template to create a file named "azure-pipelines.yml":

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  agentVersion: '2.6.4.2' #Agent version that is going to be used
  projectDirectory: '.' #path to one project in your solution
  webAppName: 'your-app-name' #your app service name
  consoleURL: 'http://console-host:8089/hdiv-console-services' #Console address. Set to empty if you do not want to use the console
  consoleToken: 'token-value' #console token provided by Hdiv
  enableToolbar: 'false' #Set value to 'true' to enable the toolbar 
  serverName: 'serverName' #Select a name for your server
  isLinux: 'false' #Set to true if you app service runs under Linux

steps:
- task: CmdLine@2
  inputs:
    script: dotnet nuget add source https://artifacts.hdivsecurity.com/nexus/service/local/nuget/nuget/ --name nexus --username $(nexusUsername) --password $(nexusPassword) --store-password-in-clear-text | dotnet add package Hdiv.AST.Profiler --version $(agentVersion)
    workingDirectory: '$(projectDirectory)'

- task: VSBuild@1
  condition: eq(lower(variables.isLinux),'false')
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: DotNetCoreCLI@2
  condition: eq(lower(variables.isLinux),'true')
  inputs:
    command: 'build'
    projects: '$(solution)'
    arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
  condition: eq(lower(variables.isLinux),'true')
  inputs:
    command: 'publish'
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) -r linux-x64'
    publishWebProjects: true
    zipAfterPublish: True

- task: AzureRmWebAppDeployment@4
  condition: eq(lower(variables.isLinux),'false')
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: '$(azureSubscription)'
    appType: 'webApp'
    WebAppName: '$(webAppName)'
    AppSettings: -HDIV_TOOLBAR_ENABLED $(enableToolbar) -COR_ENABLE_PROFILING 1 -COR_PROFILER {1adbf8d7-8774-4733-aa10-4376ba3bd37a} -COR_PROFILER_PATH_32 D:\Home\site\wwwroot\hdivsecurity\agent\x86\Hdiv.AST.Clr.Profiler.dll -COR_PROFILER_PATH_64 D:\Home\site\wwwroot\hdivsecurity\agent\x64\Hdiv.AST.Clr.Profiler.dll -CORECLR_ENABLE_PROFILING 1 -CORECLR_PROFILER {1adbf8d7-8774-4733-aa10-4376ba3bd37a} -CORECLR_PROFILER_PATH_32 D:\Home\site\wwwroot\hdivsecurity\agent\x86\Hdiv.AST.Clr.Profiler.dll -CORECLR_PROFILER_PATH_64 D:\Home\site\wwwroot\hdivsecurity\agent\x64\Hdiv.AST.Clr.Profiler.dll -HDIV_AGENT_HOME D:\Home\site\wwwroot\hdivsecurity\agent -HDIV.NET.AST.BRIDGE.ENABLED=true -HDIV_AGENT_PROFILER_PLATFORM 327680 -HDIV_LICENSE_DATA $(licenseData) -HDIV_CONSOLE_URL $(consoleURL) -HDIV_CONSOLE_TOKEN $(consoleToken) -HDIV_SERVER_NAME $(serverName)
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'

- task: AzureWebApp@1
  condition: eq(lower(variables.isLinux),'true')
  inputs:
    azureSubscription: '$(azureSubscription)'
    appType: 'webAppLinux'
    appName: '$(webAppName)'
    AppSettings: -HDIV_TOOLBAR_ENABLED $(enableToolbar) -CORECLR_ENABLE_PROFILING 1 -CORECLR_PROFILER {1adbf8d7-8774-4733-aa10-4376ba3bd37a} -CORECLR_PROFILER_PATH_64 /home/site/wwwroot/hdivsecurity/agent/x64/Hdiv.AST.Clr.Profiler.so -HDIV_AGENT_HOME /home/site/wwwroot/hdivsecurity/agent -HDIV_AGENT_PROFILER_PLATFORM 327680 -HDIV_LICENSE_DATA $(licenseData) -HDIV_CONSOLE_URL $(consoleURL) -HDIV_CONSOLE_TOKEN $(consoleToken) -HDIV_SERVER_NAME $(serverName)
    package: '$(Build.ArtifactStagingDirectory)/**/*.zip'

In the variables section, in the variable "webAppName", the proper name of the App Service should be set.

Also, in the variable "agentVersion", the Agent version that will be used must be set.

The variable "projectDirectory" must contain the path of a valid project file (.csproj) of your solution.

The variable "enableToolbar" indicates if the toolbar should be shown.

The variable "consoleURL" is used to store the address of the console. This field can be left empty if no console is going to be used.

The variable "consoleToken" contains the token of the console provided by Hdiv.

The variable "serverName" contains the name of your server. Use a name that identifies the server where the agent is installed. This name will be shown in the console.

The variable "isLinux" indicates if your web App runs under a Linux environment. If false, it is assumed that your web App runs under a Windows environment.

If you already had a .yml file for deploying with azure pipelines, you will need to merge your file with this one, merging/adding into your file the needed tasks. The task "CmdLine@2" adds the Hdiv nuget package into one of you projects and must be run before building the App. The tasks "AzureWebApp" (Linux) and "AzureRmWebAppDeployment@4" (Windows) deploy the App and must contain the input "AppSettings" that sets the environment variables that the Agent needs for running.

Set the pipeline variables

1) In dev.azure.com go Pipelines, select your pipeline and edit it.

Usage

2) Click on Variables

Usage

3) Add the required variables

Usage

Some variables need to be set:

  • azureSuscription: This variable contains your Azure subscription name and ID.

  • licenseData: The license data provided by Hdiv.

  • nexusPassword: The Nexus password for Hdiv NuGet repository provided by Hdiv.

  • nexusUsername: The Nexus user name for Hdiv NuGet repository provided by Hdiv.

Usage

Run the pipeline

1) In dev.azure.com go to "Pipelines", select your pipeline and click on "Run".

Usage

2) In the next screen, click on "Run".

Usage

3) A new job should have been created to deploy the App.

Usage

4) You can click on the job and see how the deployment process is going. After some minutes, the tasks of the job should contain a green mark.

Usage

5) Make sure that your Web App is running

Usage

6) Now, you can navigate to your deployed app and check that everything is ok. The url of the page would be the one that was defined in your App service.

Usage