在我的管道中有一项工作失败了。此故障是预料之中的,并且在检测到错误时应继续管道。 管道运行并发布单元测试 我已经完成了这项工作,管道运行到最后,并执行和发布测试。 但是,测试结果未显示,并且管道被标记为失败。
这是完整的 yaml
trigger: none
# Variable to store where the initial code checkout path
variables:
- name: BuildDir
value: Test
stages:
- stage: Checkout
pool: $(PoolName)
jobs:
- job: CheckoutRedwoodAndSealink
displayName: Checking out
steps:
- checkout: git://Redwood/Redwood@working/conifer
path: 'Redwood'
displayName: Checking out Redwood
- checkout: self
path: 'Sealink'
displayName: Checking out Sealink
- task: PowerShell@2
displayName: Change the value of BuildDir
# Store the checkout location
inputs:
targetType: 'inline'
script: 'Write-Host "##vso[task.setvariable variable=BuildDir;isOutput=true]$(Agent.BuildDirectory)"'
name: setvar
- stage: CopyThirdParty
dependsOn: Checkout
pool: $(PoolName)
variables:
# Set the build directory
BuildDir: $[stageDependencies.Checkout.CheckoutRedwoodAndSealink.outputs['setvar.BuildDir'] ]
jobs:
- job: CopyRedwoodTP
displayName: Copying Redwood Third Party
steps:
- checkout: none
- task: CmdLine@2
- task: CopyFiles@2
inputs:
SourceFolder: 'C:\Redwood\third-party'
Contents: '**'
TargetFolder: '$(BuildDir)\Redwood\third-party'
OverWrite: true
- stage: Build
dependsOn:
- Checkout
- CopyThirdParty
pool: $(PoolName)
variables:
# Set the build directory
BuildDir: $[stageDependencies.Checkout.CheckoutRedwoodAndSealink.outputs['setvar.BuildDir'] ]
jobs:
- job: Configure
displayName: Configuring CMake
steps:
- checkout: none
- task: CMake@1
inputs:
cmakeArgs: -S ./ -B ./build
workingDirectory: $(BuildDir)/Sealink
- task: CMake@1
inputs:
cmakeArgs: -S ./ -B ./build
workingDirectory: $(BuildDir)/Sealink
- job: Build
displayName: Building
dependsOn: Configure
steps:
- checkout: none
- task: CMake@1
inputs:
cmakeArgs: '--build ./build --config Debug'
workingDirectory: $(BuildDir)/Sealink
continueOnError: true
# if first build failed - try again
- job: Build2
condition: failed()
dependsOn: Build
steps:
- checkout: none
- task: CMake@1
displayName: Configuring CMake )2)
inputs:
cmakeArgs: -S ./ -B ./build
workingDirectory: $(BuildDir)/Sealink
- task: CMake@1
displayName: Building (2)
inputs:
cmakeArgs: '--build ./build --config Debug'
workingDirectory: $(BuildDir)/Sealink
- stage: RunTests
pool: $(PoolName)
dependsOn:
- Build
- Checkout
variables:
BuildDir: $[stageDependencies.Checkout.CheckoutRedwoodAndSealink.outputs['setvar.BuildDir'] ]
jobs:
- job: RunTests
displayName: Running Unit Tests
continueOnError: true
steps:
- checkout: none
- task: PowerShell@2
inputs:
targetType: 'inline'
script: '$(BuildDir)/Sealink/build/UnitTesting/Debug/Test.exe --gtest_output="xml:./TestResults/"'
- stage: Publish
pool: $(PoolName)
dependsOn:
- RunTests
- Checkout
jobs:
- job: publish
steps:
- checkout: none
- task: PublishTestResults@2
displayName: Publishng unit test results
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/TestResults'
failTaskOnFailedTests: true
通过使用 continueOnError 管道继续运行,但不显示测试结果
确保您的测试已运行并且测试结果已成功生成。以下是我的yaml供您参考。
steps:
- script: |
cmake -B build && cmake --build build
displayName: 'Build'
- script: |
cmake -E chdir build ctest -T Test
displayName: 'Test'
- task: PublishTestResults@2
inputs:
testResultsFormat: 'CTest'
testResultsFiles: '**/Test.xml'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Agent.BuildDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
测试结果:
您分享的yaml中,只有build,没有test。您可以使用
-T
选项,然后使用 ctest
来生成测试结果文件 Test.xml
。该文件将在当前构建目录下的Testing目录中生成。您可以在管道中添加 PublishBuildArtifacts@1
任务以进一步检查。