Like all steps templates, the dotNetCore steps template can be nested in the stages template or directly in steps lists. However, this template is primarily intended to be nested into other steps templates. To provide dotNetCore tasks in other steps templates this template is nested within them. This is so that the common list of steps is not copied from one template to another.
- The dotNetTests steps template nests the dotNetCore template for dotNet restore tasks
- The sonarQube steps template nests the dotNetCore template for dotNet restore and build tasks
- The containerImage steps template nests the dotNetCore template for dotNet publish tasks before the docker build tasks
- The visualStudioTest steps template nests the dotNetCore template for dotNet build tasks before the Visual Studio Test tasks
command options are build, publish, and pack:
- Build a project for code analysis or test jobs. Optional publish pipeline artifact
- Publish a project for container image build. Optional publish pipeline artifact
- Pack project and push Nuget package artifact and symbols to feed
The following example shows how to insert the dotNetCore steps template into the stages template with the minimum required params. Build a dotNet project and publish a pipeline artifact. This is useful if you want to download the build artifact into other jobs in all stages.
Note: when using the dotNetTests, sonarQube, containerImage, or visualStudioTest templates, using the dotNetCore template directly as shown below would not be needed as it's nested into these templates.
name: $(Build.Repository.Name)_$(Build.SourceVersion)_$(Build.SourceBranchName) # name is the format for $(Build.BuildNumber)
parameters:
# params to pass into stages.yaml template:
- name: projects # pattern to match of projects to build, publish, or pack
type: string
default: '**.csproj'
- name: command
type: string
default: build
values:
- build
- publish
- name: buildPool # Nested into pool param of build jobs
type: object
default:
vmImage: 'ubuntu-18.04'
# parameter defaults in the above section can be set on the manual run of a pipeline to override
resources:
repositories:
- repository: templates # Resource identifier for template usage
type: github
name: fitchtech/AzurePipelines # This repository
ref: refs/tags/v1 # The tagged release of the repository
endpoint: GitHub # Azure Service Connection Name
trigger:
branches:
include:
- master # CI Trigger on commit to master
tags:
include:
- v*.*.*-* # CI Trigger when tag matches format
extends:
# template: file path at repo resource id to extend from
template: stages.yaml@templates
# parameters: within stages.yaml@templates
parameters:
# code: jobList inserted into code stage in stages
# build: jobList inserted into build stage in stages
build:
- job: dotNetBuild # job name must be unique within stage
displayName: 'dotNet Build Projects' # job display name
pool: ${{ parameters.buildPool }} # param passed to pool of build jobs
dependsOn: [] # job does not depend on other jobs
# variables:
# key: 'value' # pairs of variables scoped to this job
steps:
# - template: for dotNetCore steps
- template: steps/build/dotNetCore.yaml
# parameters within dotNetCore.yaml template
parameters:
# preSteps:
# - task: add preSteps into job
command: ${{ parameters.command }} # default in template is build
projects: ${{ parameters.projects }} # pattern to match of projects to build
publishEnabled: true # Set publishEnabled true to publish artifact of dotNet build or publish outputs
# postSteps:
# - task: add postSteps into job
# - job: insert additional jobs into the build stage
# deploy: deploymentList inserted into deploy stage in stages param
# promote: deploymentList inserted into promote stage in stages param
# test: jobList inserted into test stage in stages param
# reject: deploymentList inserted into reject stage in stages param
The following example shows inserting a steps template into the steps section. This is to show parameter usage in the template. See the Insert Steps Templates into Stages Template section above for using this template in the stages template
steps:
# template: insert dotNetCore build and publish pipeline artifact steps into job
- template: steps/build/dotNetCore.yaml
parameters:
# When nesting multiple steps templates into a single job add clean, checkout, and download params set to false.
# checkout: self # preSteps checkout step enabled by default to checkout the source repo
download: false # disables preSteps download steps
preSteps:
- script: echo 'add preSteps stepsList to job' # list of tasks that run before the main steps of the template. Inserted into steps after checkout/download
command: publish # default: build | publish | restore
# packageType: runtime # sdk is the default, only set this to override sdk with runtime
# version: '3.1.x' # UseDotNet@2 version number by default, set to null to skip step
projects: '**.csproj' # pattern match of projects or solution to build or publish
configuration: Release # dotNet configuration flag, e.g. configuration: Release or configuration: Debug
publishEnabled: true # Set publishEnabled true to publish artifact of dotNet build or publish outputs
# feedRestore: '' # Azure DevOps Artifacts Feed
# arguments: '' # Output and no-restore arguments are injected for you. This param is for inserting any additional build/publish args for the task
postSteps:
- script: echo 'add postSteps stepsList to job' # list of tasks that run after the main steps of the template. Inserted into steps before publish/clean
# template: insert dotNetCore pack and push Nuget artifact steps into job
- template: steps/build/dotNetCore.yaml
parameters:
# When nesting multiple steps templates into a single job add clean, checkout, and download params set to false.
checkout: false # disables preSteps checkout steps
download: false # disables preSteps download steps
preSteps:
- script: echo 'add preSteps stepsList to job' # list of tasks that run before the main steps of the template. Inserted into steps after checkout/download
# packageType: runtime # sdk is the default, only set this to override sdk with runtime
# version: '3.1.x' # UseDotNet@2 version number by default, set to null to skip step
searchPatternPack: '**.csproj' # pattern match of projects or solution to build or publish
searchPatternPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
includeSymbols: true # dotNet pack include symbols
publishSymbols: true # enable publish symbols task after dotNet pack
configuration: Debug # dotNet configuration flag, e.g. configuration: Release or configuration: Debug
postSteps:
- script: echo 'add postSteps stepsList to job' # list of tasks that run after the main steps of the template. Inserted into steps before publish/clean