|
| 1 | +parameters: |
| 2 | + name: '' |
| 3 | + displayName: '' |
| 4 | + vmImage: '' |
| 5 | + outputDirectory: '' |
| 6 | + artifactName: '' |
| 7 | + timeoutInMinutes: 120 |
| 8 | + |
| 9 | +jobs: |
| 10 | + - job: ${{ parameters.name }} |
| 11 | + displayName: ${{ parameters.displayName }} |
| 12 | + timeoutInMinutes: ${{ parameters.timeoutInMinutes }} |
| 13 | + |
| 14 | + pool: |
| 15 | + vmImage: ${{ parameters.vmImage }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - checkout: self # self represents the repo where the initial Pipelines YAML file was found |
| 19 | + clean: false # whether to fetch clean each time |
| 20 | + submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules |
| 21 | + persistCredentials: true |
| 22 | + |
| 23 | + - task: UseDotNet@2 |
| 24 | + displayName: 'Use .NET' |
| 25 | + inputs: |
| 26 | + packageType: 'sdk' |
| 27 | + useGlobalJson: true |
| 28 | + |
| 29 | + - script: dotnet tool restore |
| 30 | + displayName: 'Restore dotnet tools' |
| 31 | + |
| 32 | + - pwsh: | |
| 33 | + .\build.ps1 |
| 34 | + displayName: 'Update Release Notes' |
| 35 | + continueOnError: false |
| 36 | +
|
| 37 | + - script: dotnet build -c Release |
| 38 | + displayName: 'dotnet build' |
| 39 | + continueOnError: false |
| 40 | + |
| 41 | + - script: dotnet test -c Release --no-build --logger:trx --collect:"XPlat Code Coverage" --results-directory TestResults --settings coverlet.runsettings |
| 42 | + displayName: 'Run tests' |
| 43 | + continueOnError: true # Allow continuation even if tests fail |
| 44 | + |
| 45 | + - task: PublishTestResults@2 |
| 46 | + inputs: |
| 47 | + testResultsFormat: VSTest |
| 48 | + testResultsFiles: '**/*.trx' #TestResults folder usually |
| 49 | + testRunTitle: ${{ parameters.name }} |
| 50 | + mergeTestResults: true |
| 51 | + failTaskOnFailedTests: false |
| 52 | + publishRunAttachments: true |
| 53 | + |
| 54 | + - pwsh: | |
| 55 | + $coverageFiles = Get-ChildItem -Path "$(Build.SourcesDirectory)/TestResults" -Filter "*.cobertura.xml" -Recurse |
| 56 | + $hasCoverageFiles = $coverageFiles.Count -gt 0 |
| 57 | + Write-Host "##vso[task.setvariable variable=HasCoverageFiles]$hasCoverageFiles" |
| 58 | + displayName: 'Check for Coverage Files' |
| 59 | + condition: always() |
| 60 | + continueOnError: true |
| 61 | +
|
| 62 | + - task: reportgenerator@5 |
| 63 | + displayName: ReportGenerator |
| 64 | + # Only run if coverage files exist |
| 65 | + condition: and(always(), eq(variables['HasCoverageFiles'], 'True')) |
| 66 | + continueOnError: true |
| 67 | + inputs: |
| 68 | + reports: '$(Build.SourcesDirectory)/TestResults/**/*.cobertura.xml' |
| 69 | + targetdir: '$(Build.SourcesDirectory)/coveragereport' |
| 70 | + reporttypes: 'HtmlInline_AzurePipelines;Cobertura;Badges' |
| 71 | + assemblyfilters: '-xunit*' |
| 72 | + publishCodeCoverageResults: true |
| 73 | + |
| 74 | + - publish: $(Build.SourcesDirectory)/coveragereport |
| 75 | + displayName: 'Publish Coverage Report' |
| 76 | + # Only run if coverage files exist |
| 77 | + condition: and(always(), eq(variables['HasCoverageFiles'], 'True')) |
| 78 | + continueOnError: true |
| 79 | + artifact: 'CoverageReports-$(Agent.OS)-$(Build.BuildId)' |
| 80 | + |
| 81 | + - script: dotnet pack -c Release --no-build -o $(Build.ArtifactStagingDirectory)/nuget |
| 82 | + displayName: 'Create packages' |
| 83 | + |
| 84 | + - task: PublishBuildArtifacts@1 |
| 85 | + displayName: 'Publish artifacts' |
| 86 | + inputs: |
| 87 | + PathtoPublish: '$(Build.ArtifactStagingDirectory)/nuget' |
| 88 | + ArtifactName: 'nuget' |
| 89 | + publishLocation: 'Container' |
| 90 | + |
| 91 | + - script: 'echo 1>&2' |
| 92 | + failOnStderr: true |
| 93 | + displayName: 'If above is partially succeeded, then fail' |
| 94 | + condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues') |
0 commit comments