How to send dynamic Test plan Id and Test suite Id in a classic pipeline in Visual Studio Test task

Murali, Sanjaykrishnan 0 Reputation points
2025-03-18T05:23:37.5333333+00:00

User's image

These field are not accepting environment variables since they are dropdowns. Is there any alternate way to dynamically send those fields since I want to execute multiple Test Plans and Suites in a Single pipeline without creating multiple ones.

Azure DevOps
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Harshitha Veeramalla 806 Reputation points Microsoft External Staff
    2025-03-24T11:11:23.4333333+00:00

    Hi Murali, Sanjaykrishnan,

    In your YAML file define the testPlanId and testSuiteId as pipeline variables.

    enter image description here

    and use these variables in the VS as VS Test Task using $(variableName).

    enter image description here

    
    trigger:  
    
    - master    
    
    pool:  
    
    vmImage: 'windows-2022'
    
    variables:  
    testPlanId: '$(testPlanId)' 
    testSuiteId: '$(testSuiteId)'    
    
    steps:  
    
    - task: UseDotNet@2  
    
    inputs:  
    packageType: 'sdk'  
    version: '5.x'  
    installationPath: $(Agent.ToolsDirectory)/dotnet    
    
    - script: |  
    
    echo "##vso[task.setvariable variable=testPlanId]$(newTestPlanId)"  
    echo "##vso[task.setvariable variable=testSuiteId]$(newTestSuiteId)"  
    displayName: 'Set Test Plan and Suite IDs'    
    
    - task: VSTest@2  
    
    inputs: 
    testSelector: 'TestPlan'  
    testPlan: '$(testPlanId)'  
    testSuite: '$(testSuiteId)'  
    searchFolder: '$(System.DefaultWorkingDirectory)'
    

    Now when you run the pipeline the VS Test task will use the set Test Plan ID and Test Suite ID.


    Hope this Helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.