Monday 31 August 2020

Continuous Integration test & build

 In our previous post we created a simple YAML file that 

Trigger: when either our dev or prod branch was pushed to the repo

Pool: Specify the build environment, below we use Microsoft, but you have options.

variables: we specify variables with names, so below when we use '$(BuildConfiguration)' its replaces with 'Release'

next come our steps, they are made up of tasks each tasks does something hopefully valuable in our deployment, lets now direct the tasks that make up our first and only step

however these steps don't really work for us so just delete them all as a matter of fact get rid of the solution and buildPlatform variables, this is because otb this yml file is optimized for Visual Studio Senior

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
dev
prod

pool:
  vmImage'windows-latest'

variables:
  buildConfiguration'Release'

So when done you should have something like the above, first lets add a section to test our code


steps:
# Execute xunit tests
taskDotNetCoreCLI@2
  displayName'xUnit unit tests'
  inputs
    commandtest
    projects'**/*tests/*.csproj'
    arguments'--configuration $(buildConfiguration)'

now lets add a failing test to any of your unit test files just to see what happens

        [Fact]
        public void TestToFail() => Assert.True(false);

next save and push your code, and check out the pipeline

now our pipline failed but click the published test run and you'll see something like the following 

which is a pretty cool dashboard.

Now lets remove that failing test and add a task to build our project


# Build dotnet core project
taskDotNetCoreCLI@2
  displayName'dotnet build Tic tac toe : $(buildConfiguration)'
  inputs:
    commandbuild
    projects'**/*source/*.csproj'
    

if we inspect the results we can see our two tasks executed.

 now that we have tested and built our project where do we deploy it? well lets tackle that in our next post.