Pipelines

Ever since I started using Azure Devops for source control, I always looked at Azure hosting as a scary monster! It looked huge and menacing. I would think of it as a great tool for someone who spends many hours learning all the ins and outs of it.
However having since deployed my first website to Azure web app hosting, I find myself looking at Azure in a new way. It can be used even on a very small scale, without much knowledge of the wholesome feature it can provide.

For future reference, and for anyone else this may help; I’ll be documenting my experience over a few posts of how it went.

First stop is Devops to create a build pipeline.

I went to Pipelines and hit ‘New Pipeline’ to create my build line. My code is stored in DevOps so I selected ‘Azure Repos Git’. Selected my project and configured it using ASP.NET.
This created a basic YAML file (stands for ‘Yet Another Markup Language’), from which the build will run.

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  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: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

I hit the ‘Save and run’ button to see if it would work, and as you guessed – it failed. The reason it failed was, I am using a NuGet package from Telerik which is on a subscription and therefore needs login details to be able to use it. Since I hadn’t given DevOps access it failed.

I followed this post [Azure DevOps and Telerik NuGet Packages] to add an Azure secret with the Telerik login details. It is very easy to follow, with one point that needs mentioning:
When adding the secrets to the pipeline, it must be added before any build is set. Otherwise the build will fail. Whilst this should seem blindingly obvious it took me a few tries to realise it.

The final YAML included another task (I included it the first thing after steps – line 12):

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '$(ProjectName)/$(ProjectName).csproj'
    feedsToUse: 'config'
    nugetConfigPath: 'NuGet.config'
    externalFeedCredentials: 'Telerik Feed'

Once that has been done the build should all run smoothly (assuming of course the code builds).

In part 2 we’ll take a look at getting started with Azure hosting.

Series NavigationDeploying to Azure – part 2, Getting started with Azure hosting >>

2 Comments

  • Excellent, I look forward to the rest of the series. Been contemplating this myself for some time, but (like you) I was put off by the seeming complexity of Azure.

    One request, please could you include the yaml in your posts, as that would make it easier to see what you did.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.