diff --git a/eng/pipelines/templates/steps/apiview-review-gen.yml b/eng/pipelines/templates/steps/apiview-review-gen.yml index 4403b9341c8..4d5afdb4c18 100644 --- a/eng/pipelines/templates/steps/apiview-review-gen.yml +++ b/eng/pipelines/templates/steps/apiview-review-gen.yml @@ -32,9 +32,11 @@ steps: pathtoPublish: '$(Build.ArtifactStagingDirectory)/' artifactName: 'apiview' -- pwsh: | - $requestUrl = ${{parameters.APIViewURL}}/reviewgen/update?path=apiview&buildId=$(Build.BuildId) - Write-Host $requestUrl - $resp = Invoke-RestMethod $requestUrl - Write-Host $resp - displayName: 'Send Request to APIView' \ No newline at end of file +- task: Powershell@2 + displayName: 'Send Request to APIView to Update Token files' + condition: succeededOrFailed() + inputs: + pwsh: true + filePath: $(Build.SourcesDirectory)/eng/scripts/Apiview-Update-Generated-Review.ps1 + arguments: > + -BuildId $(Build.BuildId) \ No newline at end of file diff --git a/eng/scripts/Apiview-Update-Generated-Review.ps1 b/eng/scripts/Apiview-Update-Generated-Review.ps1 new file mode 100644 index 00000000000..35e27fd70e0 --- /dev/null +++ b/eng/scripts/Apiview-Update-Generated-Review.ps1 @@ -0,0 +1,39 @@ +[CmdletBinding()] +param ( + [Parameter(Mandatory = $true)] + [string]$BuildId, + [string]$RepoName = "azure/azure-sdk-tools", + [string]$ArtifactName = "apiview", + [string]$ApiviewUpdateUrl = "https://apiview.dev/review/UpdateApiReview" +) + +#################################################################################################################### + +# This script is called by tools - generate--apireview pipelines to send a request to APIView server to +# to notify that generated code file is ready and published. APIView server pulls this code file from artifact and +# uploads into APIView. This offline step abstracts and protects APIView server resources so caller doesn't have to +# know about APIView server. Pipline will publish an artifact 'apiview' before this script is called + +# Script will send a request to APIView with build ID, artifact name and repo name as params. +# Sample request is as follows: +# https://apistaging.test.dev/review/UpdateApiReview?repoName=azure/azure-sdk-tools&buildId=1742433&artifact=apiview + +#################################################################################################################### + +$query = [System.Web.HttpUtility]::ParseQueryString('') +$query.Add('artifact', $ArtifactName) +$query.Add('buildId', $BuildId) +$query.Add('repoName', $repoName) +$uri = [System.UriBuilder]$APIViewUri +$uri.query = $query.toString() +Write-Host "Request URI: $($uri.Uri.OriginalString)" +try +{ + $Response = Invoke-WebRequest -Method 'GET' -Uri $uri.Uri -MaximumRetryCount 3 + Write-Host "Response status : $($Response.StatusCode)" +} +catch +{ + Write-Host "Error $StatusCode - Exception details: $($_.Exception.Response)" + exit 1 +} \ No newline at end of file