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
- task: DotNetCoreCLI@2
displayName: 'xUnit unit tests'
inputs:
command: test
projects: '**/*tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
# Build dotnet core project
- task: DotNetCoreCLI@2
displayName: 'dotnet build Tic tac toe : $(buildConfiguration)'
inputs:
command: build
projects: '**/source/*.csproj'
# setup azure infrastructure
- task: AzurePowerShell@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
- task: DotNetCoreCLI@2
displayName: 'dotnet publish --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
inputs:
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
command: publish
publishWebProjects: false
projects: '**/source/*.csproj'
zipAfterPublish: false
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.
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'TicTacToeAPI'