Azure devops 如何在Azure YAML管道中将布尔值指定为变量?
我正在尝试设置一个YAML来支持Azure DevOps中的调试和发布管道。我希望能够禁用和启用不同版本的测试运行(因为在调试版本上再次运行测试是多余的) 我试过这样做Azure devops 如何在Azure YAML管道中将布尔值指定为变量?,azure-devops,yaml,azure-pipelines,Azure Devops,Yaml,Azure Pipelines,我正在尝试设置一个YAML来支持Azure DevOps中的调试和发布管道。我希望能够禁用和启用不同版本的测试运行(因为在调试版本上再次运行测试是多余的) 我试过这样做 - task: VSTest@2 displayName: test (net framework) enabled: $(enableTesting) inputs: vsTestVersion: '16.0' testSelector: 'testAssemblies' testAssem
- task: VSTest@2
displayName: test (net framework)
enabled: $(enableTesting)
inputs:
vsTestVersion: '16.0'
testSelector: 'testAssemblies'
testAssemblyVer2: |
**/*Tests.dll
!**/*TestAdapter.dll
!**/obj/**
searchFolder: '$(System.DefaultWorkingDirectory)'
codeCoverageEnabled: true
testRunTitle: '.net Framework Back End Tests'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
变量“enableTesting”在变量窗口中定义为false
但对于已启用的或类似项,此错误的值“$(enableTesting)”无效。看起来它将变量值视为字符串而不是布尔值
我也试过这样
- task: VSTest@2
displayName: test (net framework)
enabled: eq(variables.enableTesting, true)
inputs:
vsTestVersion: '16.0'
testSelector: 'testAssemblies'
testAssemblyVer2: |
**/*Tests.dll
!**/*TestAdapter.dll
!**/obj/**
searchFolder: '$(System.DefaultWorkingDirectory)'
codeCoverageEnabled: true
testRunTitle: '.net Framework Back End Tests'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
并通过适当修改错误消息得到相同的结果
如果我这样做
- task: VSTest@2
displayName: test (net framework)
enabled: false
inputs:
vsTestVersion: '16.0'
testSelector: 'testAssemblies'
testAssemblyVer2: |
**/*Tests.dll
!**/*TestAdapter.dll
!**/obj/**
searchFolder: '$(System.DefaultWorkingDirectory)'
codeCoverageEnabled: true
testRunTitle: '.net Framework Back End Tests'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
然后它就可以正常工作了,但这是不可重用的。您不能将变量放入
启用:
属性中,最好的方法是使用:
将其放入测试任务中:
- task: VSTest@2
displayName: test (net framework)
inputs:
vsTestVersion: '16.0'
testSelector: 'testAssemblies'
testAssemblyVer2: |
**/*Tests.dll
!**/*TestAdapter.dll
!**/obj/**
searchFolder: '$(System.DefaultWorkingDirectory)'
codeCoverageEnabled: true
testRunTitle: '.net Framework Back End Tests'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
condition: and(succeeded(), eq(variables['enableTesting'], 'true'))
- task: VSTest@2
displayName: test (net framework)
inputs:
vsTestVersion: '16.0'
testSelector: 'testAssemblies'
testAssemblyVer2: |
**/*Tests.dll
!**/*TestAdapter.dll
!**/obj/**
searchFolder: '$(System.DefaultWorkingDirectory)'
codeCoverageEnabled: true
testRunTitle: '.net Framework Back End Tests'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
condition: and(succeeded(), eq(variables['enableTesting'], 'true'))