I have a solution that contains the following
Several Asp.net Projects(Microservices and Gateway)
.net Core + Angular 8 (Front End)
When i hit the build button in visual studio every project is built.I have created a repo and uploaded the solution.Now i'm trying to figure out how to setup the pipeline to build each microservice and deploy them to individual Azure Web Apps.
I have the following Pipeline for the Angular Project.Should i define separate tasks like this? Is there a way to replicate visual studio build here?
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: Npm@1
inputs:
command: install
workingDir: 'd:\a\1\s\Ok.Web\ClientApp'
- task: Npm@1
inputs:
command: custom
workingDir: 'd:\a\1\s\Ok.Web\ClientApp'
customCommand: run build
- task: CopyFiles@2
inputs:
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
You may apply one of two approaches here:
In both things you may use templates to avoid reapeting yourself. So you will define common tasks for building .NET project and then use them in pipelines. I made recently blog post about this , but please take a look on documentation too.
To achieve that you need to define first a yaml file with common steps. For instance:
parameters:
- name: buildConfiguration # name of the parameter; required
default: 'Release'
- name: projectFolder
default: ' '
steps:
- task: DotNetCoreCLI@2
displayName: Restore nuget packages
inputs:
command: restore
projects: '*.csproj'
workingDirectory: '${{ parameters.projectFolder}}'
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: '${{ parameters.projectFolder}}'
arguments: '--configuration ${{ parameters.buildConfiguration }}'
# You just added coverlet.collector to use 'XPlat Code Coverage'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '*Tests/*.csproj'
arguments: '--configuration ${{ parameters.buildConfiguration }} --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true'
workingDirectory: '${{ parameters.projectFolder}}'
- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool
- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:${{ parameters.projectFolder}}/coverlet/reports -reporttypes:"Cobertura"
displayName: Create reports
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: ${{ parameters.projectFolder}}/coverlet/reports/Cobertura.xml
And then invoke this file from you main build file:
variables:
buildConfiguration: 'Release'
projectFolder: 'path to your project'
steps:
- template: build-and-test.yaml
parameters:
buildConfiguration: $(buildConfiguration)
- script: echo Some steps to create artifacts!
displayName: 'Run a one-line script'
In approach numer 1 you will build all project even if you change just a one project, so I would recommend you approach number 2. For this you may define multiple pipelines (one per project) and limit trigger to changes in specific folder. Please take a look here .
Here you have an example how you can limit trigger to specific folder for master branch:
trigger:
branches:
include:
- master
paths:
include:
- gated-checkin-with-template/*
exclude:
- gated-checkin-with-template/azure-pipelines-gc.yml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.