azureazure-devopsrest-assuredazure-pipelines-yaml

/azure-pipeline.yml (Line: 52, Col: 9): Unexpected value 'outputs' - Error in Azure build pipeline


I have set up RestAssured API project and want to integrate it with Azure DevOps build. I can't seem to solve this error that /azure-pipeline.yml (Line: 52, Col: 9): Unexpected value 'outputs' with my YAML code.

This Above is the screenshot of the error when I try to start the pipeline run.

In the YAML, I am trying to download chrome driver and set its path into an env variable so it can be used during test execution.

name: API Tests Pipeline

trigger: none

pool:
  vmImage: "windows-2022"

stages:
  - stage: Build
    displayName: "Build Stage"
    jobs:
      - job: DownloadChromeDriver
        displayName: "Download ChromeDriver"
        steps:
          - powershell: |
              # Step to download the latest ChromeDriver
              $fixedChromeDriverVersion = "137.0.7151.119"
              $chromeDriverDownloadUrl = "https://storage.googleapis.com/chrome-for-testing-public/$fixedChromeDriverVersion/win64/chromedriver-win64.zip"

              $zipPath = "$(Build.ArtifactStagingDirectory)\chromedriver-win64.zip"
              $extractPath = "$(Build.ArtifactStagingDirectory)\chromedriver-win64"

              Write-Host "Downloading ChromeDriver from $chromeDriverDownloadUrl"
              Invoke-WebRequest -Uri $chromeDriverDownloadUrl -OutFile $zipPath -ErrorAction Stop

              # Ensure the ZIP file was downloaded successfully
              if (-Not (Test-Path -Path $zipPath) -or (Get-Item $zipPath).Length -eq 0) {
                  Write-Host "Download failed or file is empty: $zipPath"
                  Throw "Download failed."
              }

              # Expand the ZIP archive
              Add-Type -AssemblyName System.IO.Compression.FileSystem
              [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $extractPath)

              $driverPath = Join-Path -Path $extractPath -ChildPath "chromedriver-win64/chromedriver.exe"

              if (-Not (Test-Path -Path $driverPath)) {
                  Write-Host "chromedriver.exe not found at $driverPath"
                  Throw "Chromedriver extraction failed."
              }

              # Set the environment variable for the entire pipeline
              Write-Host "##vso[task.setvariable variable=CHROME_DRIVER_PATH;isOutput=true]$driverPath"
              Write-Host "ChromeDriver Path set to: $driverPath"

              # Grant execution permissions
              icacls $driverPath /grant Everyone:"RX"
            displayName: "Download and Set ChromeDriver Path"

        outputs:
          chromeDriverPath: $(CHROME_DRIVER_PATH)

      - job: MavenBuild
        displayName: "Build and Test"
        dependsOn: DownloadChromeDriver
        variables:
          CHROME_DRIVER_PATH: $[dependencies.DownloadChromeDriver.outputs['chromeDriverPath']]
        steps:
          - task: Maven@4
            displayName: "Maven Build and Install"
            inputs:
              mavenPomFile: "Automation/pom.xml"
              goals: "clean install"
              publishJunitResults: true
              testResultsFormat: "JUnit"
              testResultsFiles: "**/target/surefire-reports/testng-results.xml"
              javaHomeOption: "JDKVersion"
              jdkArchitectureOption: "x64"
            env:
              CHROME_DRIVER_PATH: $(CHROME_DRIVER_PATH)

Solution

  • You have a syntax error that is causing your issues. This is not valid syntax:

    outputs:
              chromeDriverPath: $(CHROME_DRIVER_PATH)
    

    You're going to want to remove that line and add a new step name inside your powershell code following correct syntax as described here.

    - job: DownloadChromeDriver
            displayName: "Download ChromeDriver"
            steps:
              - powershell: |
                  # ...existing code...
                  Write-Host "##vso[task.setvariable variable=CHROME_DRIVER_PATH;isOutput=true]$driverPath"
                  # ...existing code...
                name: setChromeDriverPath # <-- Add a step name here
                displayName: "Download and Set ChromeDriver Path"
    

    And then, consume this variable like this:

    - job: MavenBuild
            displayName: "Build and Test"
            dependsOn: DownloadChromeDriver
            variables:
              CHROME_DRIVER_PATH: $[ dependencies.DownloadChromeDriver.outputs['setChromeDriverPath.CHROME_DRIVER_PATH'] ]
            steps:
              # ...existing code...