Skip to content

Commit

Permalink
ABZU-69885-Add lease to pipeline (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiviteshT authored Mar 3, 2023
1 parent 63fc19f commit eda18dc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Deployment/add-lease.ps1
Original file line number Diff line number Diff line change
@@ -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;]"
}
14 changes: 14 additions & 0 deletions Deployment/templates/retain-pipeline.yml
Original file line number Diff line number Diff line change
@@ -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)'"
12 changes: 11 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ variables:
- group: Covscan-vars
- name: SdkVersion
value: "6.0.x"
- name: WindowPool
value: "NautilusBuild"

resources:
repositories:
Expand Down Expand Up @@ -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)
tfstateStorageAccountName: $(APIM_TFSTATE_STORAGE_ACCOUNT_NAME)

- job: PostDeploymentActions
dependsOn:
- LiveDeployApp
pool: $(WindowPool)
displayName: Post Deployment Actions
steps:
- template: Deployment/templates/retain-pipeline.yml

0 comments on commit eda18dc

Please sign in to comment.