diff --git a/Deployment/add-lease.ps1 b/Deployment/add-lease.ps1 new file mode 100644 index 000000000..1799b4557 --- /dev/null +++ b/Deployment/add-lease.ps1 @@ -0,0 +1,28 @@ +Param( + [Parameter(mandatory=$true)][int]$daysValid, + [Parameter(mandatory=$true)][string]$accessToken, + [Parameter(mandatory=$true)][int]$definitionId, + [Parameter(mandatory=$true)][string]$ownerId, + [Parameter(mandatory=$true)][int]$buildId, + [Parameter(mandatory=$true)][string]$collectionUri, + [Parameter(mandatory=$true)][string]$teamProject +) + +try{ + $contentType = "application/json"; + $headers = @{ Authorization = 'Bearer $accessToken' }; + $rawRequest = @{ daysValid = $daysValid; definitionId = $definitionId; ownerId = $ownerId; protectPipeline = $false; runId = $buildId }; + $request = ConvertTo-Json @($rawRequest); + $uri = "$collectionUri$teamProject/_apis/build/retention/leases?api-version=7.0"; + + Write-Host $request + Write-Host $uri + + Invoke-RestMethod -uri $uri -method POST -Headers $headers -ContentType $contentType -Body $request; + + Write-Host "Pipeline will be retained for $daysValid days" +} +catch{ + Write-Host $_ + Write-Host "##vso[task.complete result=SucceededWithIssues;]" +} diff --git a/Deployment/templates/retain-pipeline.yml b/Deployment/templates/retain-pipeline.yml new file mode 100644 index 000000000..3a47069b1 --- /dev/null +++ b/Deployment/templates/retain-pipeline.yml @@ -0,0 +1,14 @@ +steps: + - task: PowerShell@2 + condition: and(succeeded(), not(canceled())) + displayName: Retain Live Release + inputs: + targetType: filePath + filePath: "$(Build.SourcesDirectory)/Deployment/add-lease.ps1" + arguments: "-daysValid 365 + -accessToken '$(System.AccessToken)' + -definitionId $(System.DefinitionId) + -ownerId 'User:$(Build.RequestedForId)' + -buildId $(Build.BuildId) + -collectionUri '$(System.CollectionUri)' + -teamProject '$(System.TeamProject)'" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4a316a222..5bf711b12 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,6 +46,8 @@ variables: - group: Covscan-vars - name: SdkVersion value: "6.0.x" + - name: WindowPool + value: "NautilusBuild" resources: repositories: @@ -705,4 +707,12 @@ stages: APIMResourceGroup: $(APIM_RESOURCE_GROUP_NAME) APIMServiceInstance: $(APIM_SERVICE_NAME) tfstateStorageAccountRG: $(APIM_TFSTATE_STORAGE_ACCOUNT_RG) - tfstateStorageAccountName: $(APIM_TFSTATE_STORAGE_ACCOUNT_NAME) \ No newline at end of file + tfstateStorageAccountName: $(APIM_TFSTATE_STORAGE_ACCOUNT_NAME) + + - job: PostDeploymentActions + dependsOn: + - LiveDeployApp + pool: $(WindowPool) + displayName: Post Deployment Actions + steps: + - template: Deployment/templates/retain-pipeline.yml