- Deploying to Azure – part 1, Creating a build pipeline
- Deploying to Azure – part 2, Getting started with Azure hosting
- Deploying to Azure – part 3, Deploying the site
- Deploying to Azure – Part 4, Adding a custom domain
- Deploying to Azure – Part 5, Continuous delivery
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: [email protected] - task: [email protected] inputs: restoreSolution: '$(solution)' - task: [email protected] 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: [email protected] 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: [email protected] 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.