We have an on-premises, TFVC setup with Azure Devops 2019. I'm building a C++ library and have set-up a multi-configuration build (Debug, Release) which works fine. However, I'd like to run a set of unit tests only when the Release configuration is building. I've added a "Visual Studio Test" task which unfortunately is running under both configurations and takes way too long under the Debug configuration. Each test is run in isolation.
I'm not seeing any options to conditionally run the task (I can't edit YAML).
Is there a way to run a task in the pipeline only for a certain configuration?
Firstly, you must have the permissions to create, edit and delete the pipeline in the project. If you do not have the permissions, you need to contact the project administrators.
Suppose the variable for the configurations is Configuration = Debug,Release
.
To run a task in the pipeline only for a certain configuration:
Configuration
variable in pipeline
Configuration
is Debug
.
if
conditional to skip the Visual Studio Test task.jobs:
- job: Build
strategy:
maxParallel: 2
matrix:
DEBUG:
Configuration: Debug
RELEASE:
Configuration: Release
steps:
- task: Bash@3
displayName: 'Show current Configuration'
inputs:
targetType: 'inline'
script: 'echo "Configuration = $(Configuration)"'
. . .
- ${{ if eq(variables['Configuration'], 'Release') }}:
- task: VSTest@2
displayName: 'VsTest - testAssemblies'
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
In this way, when the Configuration
is Debug
, the Visual Studio Test task will be skipped and hidden in the job run.
condition
to skip the Visual Studio Test task.jobs:
- job: Build
strategy:
maxParallel: 2
matrix:
DEBUG:
Configuration: Debug
RELEASE:
Configuration: Release
steps:
- task: Bash@3
displayName: 'Show current Configuration'
inputs:
targetType: 'inline'
script: 'echo "Configuration = $(Configuration)"'
. . .
- task: VSTest@2
displayName: 'VsTest - testAssemblies'
condition: eq(variables['Configuration'], 'Release')
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
In this way, when the Configuration
is Debug
, the Visual Studio Test task will be skipped but not hidden in the job run.