Monday 7 September 2020

Continuous Integration Publish Artifact

Previously we tested our code in the continuous integration stage of our devops pipeline, now we are going to package and publish our artifact so that in the future we can us it in our continuous deployment stage.

so you may have guessed it, lets open up our YAML file


trigger:
dev
prod

pool:
  vmImage'windows-latest'

variables:
  buildConfiguration'Release'

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

# Build dotnet core project
taskDotNetCoreCLI@2
  displayName'dotnet build Tic tac toe : $(buildConfiguration)'
  inputs:
    commandbuild
    projects'**/source/*.csproj'
    
# setup azure infrastructure
taskAzurePowerShell@5
  displayName'Create Azure infrastructure for tic tac toe api'
  inputs:
    azurePowerShellVersion'LatestVersion'
    azureSubscription'Pavs Subscription(6e72246e-ce95-4565-95ae-90cc69a851a1)'
    errorActionPreference'continue'
    ScriptType'FilePath'
    ScriptPath'$(Build.SourcesDirectory)\infrastructure.ps1'
    ScriptArguments'-location switzerlandnorth -name tictactoe -env dev'

We are now going to add two more tasks

the first task creates a publish artifact for you to deploy


# this tasks creates a publish artifact for you to deploy
taskDotNetCoreCLI@2
  displayName'dotnet publish --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
  inputs:
    arguments'--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    commandpublish
    publishWebProjectsfalse
    projects'**/source/*.csproj'
    zipAfterPublishfalse

and the second takes those artifacts and publishes them to a staging area for you Continuous deployment pipeline 


# this code takes all the files in $(Build.ArtifactStagingDirectory) and uploads them as an artifact of your build.
taskPublishBuildArtifacts@1
  displayName'Publish Artifact'
  inputs:
    pathtoPublish'$(Build.ArtifactStagingDirectory)' 
    artifactName'TicTacToeAPI'