Need help on yaml pipline to add if condition to see if the file is availble in path

prakash chandran 0 Reputation points
2023-03-06T13:35:10.6133333+00:00

Need help adding an if condition to see if the file is still in the path after execution Outputxunit file to display the result if it is not available choose another file

The Yaml file is attached. Some resolution will be appreciated.

Highlighted in red line need to validate the Finalouputxunit.xml is available should display result

-task:publishtestresult@2

Pipeline code

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

schedules:
- cron: "0 13 * * 1-5"
  displayName: Daily Test
  branches:
    include:
    - main
    - Feature-Sprint3
    
pool:
  vmImage: 'windows-latest'

strategy:
  matrix:
    Python 3.9:
      python.version: '3.9'
  maxParallel: 1

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  ChromeVersion:  '108.0.5359.71'
  system_accesstoken: $(System.AccessToken)
  
steps:

- task: UsePythonVersion@0
  inputs: 
    versionSpec: '$(python.version)'
    architecture: 'x64'


- script: pip install robotframework robotframework-seleniumlibrary robotframework-requests pyautogui webdrivermanager
  displayName: 'Install dependencies'

# - powershell: |
#    (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo
#   displayName: 'We want to know the Chrome version installed on this darned machine'

- script: webdrivermanager chrome:109.0.5414.74 --linkpath AUTO
  displayName: 'Manage Chrome webdriver version'
- script: pip install -U robotframework-pabot
  displayName: 'Install dependencies'

- powershell: |
   Write-Host "Robot Framework tests"
    pabot -x 'outputxunit.xml' -v ENV:$(ENV) -v BROWSER:Chrome  --include '$(Tags)' Projectname\rf-tests 
  failOnStderr: true
  displayName: 'Run Robot Framework Tests'
  continueOnError: true

- powershell: |
   Write-Host "Robot Framework tests"
    pabot  --rerunfailed 'D:\a\1\s\output.xml' -d D:\a\1\s  -o output1.xml -v ENV:$(ENV) -v BROWSER:Chrome  --include '$(Tags)' Projectname\rf-tests 
  failOnStderr: true
  displayName: 'ReRun Robot Framework Tests'
  continueOnError: true 


- powershell: |
   Write-Host "Robot Framework tests"
   cd  D:\a\1\s\
    rebot -d  D:\a\1\s\ -o FinalOutput.xml --merge 'D:\a\1\s\output.xml'  'D:\a\1\s\output1.xml'
    rebot -d  D:\a\1\s\  -x Finaloutputtxunit.xml  D:\a\1\s\FinalOutput.xml
  failOnStderr: true
  displayName: 'Merge Report'
  continueOnError: true 

- task: PublishTestResults@2
  displayName: 'Publish Test Results'
  continueOnError: false
  inputs:
    testResultsFiles: Finaloutputtxunit.xml
    publishRunAttachments: true

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: $(Build.SourcesDirectory)
    artifactName: MyBuildOutputs


User's image

Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,766 Reputation points
    2023-03-07T16:16:39.7233333+00:00
    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query.
    
    I have linked an article below that may help solve your issue. Here is what the article has to say:
    
    YAML pipelines don't have a Create work item on failure setting like classic build pipelines. Classic build pipelines are single stage, and Create work item on failure applies to the whole pipeline. YAML pipelines can be multi-stage, and a pipeline level setting may not be appropriate. To implement Create work item on failure in a YAML pipeline, you can use methods such as the Work Items - Create REST API call or the Azure DevOps CLI az boards work-item create command at the desired point in your pipeline.
    
    The following example has two jobs. The first job represents the work of the pipeline, but if it fails, the second job runs, and creates a bug in the same project as the pipeline.
    
    
    # When manually running the pipeline, you can select whether it
    # succeeds or fails.
    parameters:
    - name: succeed
      displayName: Succeed or fail
      type: boolean
      default: false
    
    trigger:
    - main
    
    pool:
      vmImage: ubuntu-latest
    
    jobs:
    - job: Work
      steps:
      - script: echo Hello, world!
        displayName: 'Run a one-line script'
    
      # This malformed command causes the job to fail
      # Only run this command if the succeed variable is set to false
      - script: git clone malformed input
        condition: eq(${{ parameters.succeed }}, false)
    
    # This job creates a work item, and only runs if the previous job failed
    - job: ErrorHandler
      dependsOn: Work
      condition: failed()
      steps: 
      - bash: |
          az boards work-item create \
            --title "Build $(build.buildNumber) failed" \
            --type bug \
            --org $(System.TeamFoundationCollectionUri) \
            --project $(System.TeamProject)
        env: 
          AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
        displayName: 'Create work item on failure'
    
    
    REFERENCE:  https://learn.microsoft.com/en-us/azure/devops/pipelines/customize-pipeline?view=azure-devops
    
    You can also check https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/?view=azure-pipelines
    
    
    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.
    
    0 comments No comments

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.