diff --git a/tools/devops/automation/templates/common/archive-html-report.yml b/tools/devops/automation/templates/common/archive-html-report.yml new file mode 100644 index 00000000000..cb4c4fed8f0 --- /dev/null +++ b/tools/devops/automation/templates/common/archive-html-report.yml @@ -0,0 +1,47 @@ +# Remove empty directories, archive the Html Report, and publish it as a pipeline artifact. +parameters: + +- name: rootFolder + type: string + +- name: artifactName + type: string + +steps: + +# Remove empty directories before archiving. +- pwsh: | + $root = "${{ parameters.rootFolder }}" + if (Test-Path $root) { + Get-ChildItem $root -Recurse -Force -Directory | + Sort-Object -Property FullName -Descending | + Where-Object { ($_ | Get-ChildItem -Force | Select-Object -First 1).Count -eq 0 } | + ForEach-Object { + Write-Host "Removing empty directory: $($_.FullName)" + Remove-Item -Force $_ + } + } + displayName: 'Remove empty directories from HtmlReport' + continueOnError: true + condition: succeededOrFailed() + +# Archive files for the Html Report so that the report can be easily uploaded as artifacts of the build. +- task: ArchiveFiles@1 + displayName: 'Archive HtmlReport' + inputs: + rootFolder: '${{ parameters.rootFolder }}' + includeRootFolder: false + archiveFile: '$(Build.ArtifactStagingDirectory)/HtmlReport.zip' + continueOnError: true + condition: succeededOrFailed() + +# Create HtmlReport artifact. This serves two purposes: +# 1. It is the way we are going to share the HtmlReport with the publish_html job that is executed on a Windows machine. +# 2. Users can download this if they want. +- task: PublishPipelineArtifact@1 + displayName: 'Publish Artifact: HtmlReport' + inputs: + targetPath: '$(Build.ArtifactStagingDirectory)/HtmlReport.zip' + artifactName: '${{ parameters.artifactName }}' + continueOnError: true + condition: succeededOrFailed() diff --git a/tools/devops/automation/templates/mac/build.yml b/tools/devops/automation/templates/mac/build.yml index a6c20308996..b564d24af9a 100644 --- a/tools/devops/automation/templates/mac/build.yml +++ b/tools/devops/automation/templates/mac/build.yml @@ -223,22 +223,9 @@ steps: continueOnError: true condition: succeededOrFailed() -# Archive files for the Html Report so that the report can be easily uploaded as artifacts of the build. -- task: ArchiveFiles@1 - displayName: 'Archive HtmlReport' - inputs: +- template: ../common/archive-html-report.yml + parameters: rootFolder: '$(BUILD_REPOSITORY_TITLE)/jenkins-results' - includeRootFolder: false - archiveFile: '$(Build.ArtifactStagingDirectory)/HtmlReport.zip' - continueOnError: true - condition: succeededOrFailed() - -- task: PublishPipelineArtifact@1 - displayName: 'Publish Artifact: HtmlReport' - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)/HtmlReport.zip' artifactName: '${{ parameters.uploadPrefix }}HtmlReport-${{ parameters.stageName }}${{ parameters.label }}-$(System.JobAttempt)' - continueOnError: true - condition: succeededOrFailed() diff --git a/tools/devops/automation/templates/tests/run-tests.yml b/tools/devops/automation/templates/tests/run-tests.yml index 55f5d8d5a7b..0ff0d43d39c 100644 --- a/tools/devops/automation/templates/tests/run-tests.yml +++ b/tools/devops/automation/templates/tests/run-tests.yml @@ -217,26 +217,10 @@ steps: continueOnError: true condition: and(ne(variables['VSTS_XML_FILES'], 0), succeededOrFailed()) -# Archive files for the Html Report so that the report can be easily uploaded as artifacts of the build. -- task: ArchiveFiles@1 - displayName: 'Archive HtmlReport' - inputs: +- template: ../common/archive-html-report.yml + parameters: rootFolder: '$(BUILD_REPOSITORY_TITLE)/jenkins-results' - includeRootFolder: false - archiveFile: '$(Build.ArtifactStagingDirectory)/HtmlReport.zip' - continueOnError: true - condition: succeededOrFailed() - -# Create HtmlReport artifact. This serves two purposes: -# 1. It is the way we are going to share the HtmlReport with the publish_html job that is executed on a Windows machine. -# 2. Users can download this if they want. -- task: PublishPipelineArtifact@1 - displayName: 'Publish Artifact: HtmlReport' - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)/HtmlReport.zip' artifactName: '${{ parameters.uploadPrefix }}HtmlReport-${{ parameters.testPrefix }}-$(System.JobAttempt)' - continueOnError: true - condition: succeededOrFailed() # Upload all the binlogs # Copy all the binlogs to a separate directory, keeping directory structure. diff --git a/tools/devops/automation/templates/windows/build.yml b/tools/devops/automation/templates/windows/build.yml index 7145baec4ee..f54bf8a9713 100644 --- a/tools/devops/automation/templates/windows/build.yml +++ b/tools/devops/automation/templates/windows/build.yml @@ -357,26 +357,10 @@ steps: continueOnError: true condition: succeededOrFailed() -# Archive files for the Html Report so that the report can be easily uploaded as artifacts of the build. -- task: ArchiveFiles@1 - displayName: 'Archive HtmlReport' - inputs: +- template: ../common/archive-html-report.yml + parameters: rootFolder: '$(Build.SourcesDirectory)/$(BUILD_REPOSITORY_TITLE)/jenkins-results' - includeRootFolder: false - archiveFile: '$(Build.ArtifactStagingDirectory)/HtmlReport.zip' - continueOnError: true - condition: succeededOrFailed() - -# Create HtmlReport artifact. This serves two purposes: -# 1. It is the way we are going to share the HtmlReport with the publish_html job that is executed on a Windows machine. -# 2. Users can download this if they want. -- task: PublishPipelineArtifact@1 - displayName: 'Publish Artifact: HtmlReport' - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)/HtmlReport.zip' artifactName: '${{ parameters.uploadPrefix }}HtmlReport-windows_integrationwindows-$(System.JobAttempt)' - continueOnError: true - condition: succeededOrFailed() - pwsh: | Write-Host "Run windows tests."