Skip to content

Commit

Permalink
Add deployment step (actions#4)
Browse files Browse the repository at this point in the history
* add release step

* add creation release

* move file to another folder

* resolve comments

* minor changes
  • Loading branch information
dmitry-shibanov authored Feb 20, 2020
1 parent 779cef9 commit 56bc081
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions images.CI/azure-pipelines/image-generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ jobs:
-VirtualNetworkSubnet $(BUILD_AGENT_SUBNET_NAME) `
-GitHubFeedToken $(GITHUB_TOKEN)

- task: PowerShell@2
displayName: 'Create release for VM deployment'
inputs:
targetType: filePath
filePath: ./images.CI/create-release.ps1
arguments: -BuildId $(Build.BuildNumber) `
-Organization $(RELEASE_TARGET_ORGANIZATION) `
-DefinitionId $(RELEASE_TARGET_DEFINITION_ID) `
-Project $(RELEASE_TARGET_PROJECT) `
-ImageName ${{ parameters.image_type }} `
-AccessToken $(RELEASE_TARGET_TOKEN)

- task: PowerShell@2
displayName: 'Clean up resources'
condition: always()
Expand Down
31 changes: 31 additions & 0 deletions images.CI/create-release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
param(
[UInt32] [Parameter (Mandatory)] $BuildId,
[String] [Parameter (Mandatory)] $Organization,
[String] [Parameter (Mandatory)] $Project,
[String] [Parameter (Mandatory)] $ImageName,
[String] [Parameter (Mandatory)] $DefinitionId,
[String] [Parameter (Mandatory)] $AccessToken
)

$Body = @{
definitionId = $DefinitionId
variables = @{
ImageBuildId = @{
value = $BuildId
}
ImageName = @{
value = $ImageName
}
}
isDraft = "false"
} | ConvertTo-Json -Depth 3

$URL = "https://vsrm.dev.azure.com/$Organization/$Project/_apis/release/releases?api-version=5.1"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("'':${AccessToken}"))
$headers = @{
Authorization = "Basic ${base64AuthInfo}"
}

$NewRelease = Invoke-RestMethod $URL -Body $Body -Method "POST" -Headers $headers -ContentType "application/json"

Write-Host "Created release: $($NewRelease._links.web.href)"

0 comments on commit 56bc081

Please sign in to comment.