Search code examples
powershellazure-devopspowershell-3.0

Outputting HTML file in Azure DevOps build YML


I have a powershell script which creates an html file and I'm new to Azure DevOps. This html file has to be compiled and produced with the build artifact. I'm not exactly sure how I go about that. Could someone point me in the right direction as to where the release notes get outputted? Do I need to add a file path based on stagingdirectory, agent?

- task: PowerShell@2
  displayName: "Generate release notes"
  inputs:
    targetType: 'inline'
    script: |
     // some stuff that's irrelevant
    [string]$fileName = ".\ReleaseNotes.html"
    $releaseNotesHtml = "<!DOCTYPE html><html><head><title>Release Notes for" + 
        $applicationName + "</title></head>" +
        "<body>"

      foreach($item in $workItemResponse.value)
      {
        $releaseNotesHtml += 
          "<div>" +
            "<h4>" + $item.fields.'System.WorkItemType' + " " + 
                  $item.fields.'System.Title' + "</h4>" +
            "<b>Description</b><br/>" +
            "<p>" + $item.fields.'System.Description' + "</p>" +
          "</div>"
      }

      $releaseNotesHtml += "</body></html>"
      #=== Write the release notes to the output file === 
      Write-Host "Starting to write release notes to: "$fileName
      $releaseNotesHtml | out-file $fileName
      Write-Host "Finished writing release notes"

Solution

  • Copy the file into the $(Build.ArtifactStagingDirectory) and then publish it as an artifact. See https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/build-artifacts?view=azure-devops&tabs=yaml