forked from microsoft/azure-pipelines-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vsts.release.yml
207 lines (188 loc) Β· 9 KB
/
.vsts.release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
parameters:
- name: version
type: string
displayName: Version
- name: derivedFrom
type: string
displayName: Derived From Version
default: latest
- name: skipTests
type: boolean
default: false
displayName: Skip Tests
# buildStageOnly is useful for testing changes of the build stage which cannot be tested
# in the ci project, like signing, without actually doing a release
- name: buildStageOnly
type: boolean
default: false
displayName: Build Stage Only
variables:
releaseBranch: releases/${{ parameters.version }}
extends:
template: .azure-pipelines/pipeline.yml
parameters:
branch: ${{ variables.releaseBranch }}
componentDetection: false
test: ${{ not(parameters.skipTests) }}
sign: true
publishArtifacts: true
${{ if not(parameters.buildStageOnly) }}:
preBuildStages:
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
- stage: Create_Release_Branch
displayName: Create Release Branch
jobs:
################################################################################
- job: Create_Release_Branch
################################################################################
displayName: Create Release Branch
pool:
vmImage: ubuntu-18.04
steps:
- checkout: self
- task: NodeTool@0
displayName: Use node 14.15.1
inputs:
versionSpec: "14.15.1"
- script: |
cd release
npm install
node createReleaseBranch.js ${{ parameters.version }} --derivedFrom=${{ parameters.derivedFrom }}
env:
EDITOR: cat
PAT: $(GithubToken)
displayName: Push release branch to GitHub
${{ if not(parameters.buildStageOnly) }}:
postBuildStages:
- stage: Release
jobs:
################################################################################
- job: publish_agent_packages
################################################################################
displayName: Publish Agents (Windows/Linux/OSX)
pool:
name: RMAgentsProdAME
steps:
# Clean
- checkout: self
clean: true
# Switch to release branch
- template: switch-branch.yml
parameters:
branch: ${{ variables.releaseBranch }}
# Download all agent packages from all previous phases
- task: DownloadBuildArtifacts@0
displayName: Download Agent Packages
inputs:
artifactName: agent
# Upload agent packages to Azure blob storage and refresh Azure CDN
- powershell: |
Write-Host "Preloading Azure modules." # This is for better performance, to avoid module-autoloading.
Import-Module AzureRM, AzureRM.profile, AzureRM.Storage, Azure.Storage, AzureRM.Cdn -ErrorAction Ignore -PassThru
if (!(Test-Path "$HOME\Documents\WindowsPowerShell\profile.ps1"))
{
Write-Host "Creating empty PowerShell profile for Enable-AzureRmAlias"
New-Item -Path "$HOME\Documents\WindowsPowerShell\profile.ps1" -ItemType File -Force | Out-Null
}
Enable-AzureRmAlias -Scope CurrentUser
$uploadFiles = New-Object System.Collections.ArrayList
$certificateThumbprint = (Get-ItemProperty -Path "$(ServicePrincipalReg)").ServicePrincipalCertThumbprint
$clientId = (Get-ItemProperty -Path "$(ServicePrincipalReg)").ServicePrincipalClientId
Write-Host "##vso[task.setsecret]$certificateThumbprint"
Write-Host "##vso[task.setsecret]$clientId"
Login-AzureRmAccount -ServicePrincipal -CertificateThumbprint $certificateThumbprint -ApplicationId $clientId -TenantId $(TenantId)
Select-AzureRmSubscription -SubscriptionId $(SubscriptionId)
$storage = Get-AzureRmStorageAccount -ResourceGroupName vstsagentpackage -AccountName vstsagentpackage
$versionDir = "${{ parameters.version }}"
Get-ChildItem -LiteralPath "$(System.ArtifactsDirectory)/agent" | ForEach-Object {
$target=$_
Get-ChildItem -LiteralPath "$(System.ArtifactsDirectory)/agent/$target" -Include "*.zip","*.tar.gz" | ForEach-Object {
$executable = $_
Write-Host "Uploading $executable to BlobStorage vstsagentpackage/agent/$versionDir"
Set-AzureStorageBlobContent -Context $storage.Context -Container agent -File "$(System.ArtifactsDirectory)/agent/$target/$executable" -Blob "$versionDir/$executable" -Force
$uploadFiles.Add("/agent/$versionDir/$executable")
}
}
Write-Host "Purge Azure CDN Cache"
Unpublish-AzureRmCdnEndpointContent -EndpointName vstsagentpackage -ProfileName vstsagentpackage -ResourceGroupName vstsagentpackage -PurgeContent $uploadFiles
Write-Host "Force Refresh Azure CDN Cache"
Publish-AzureRmCdnEndpointContent -EndpointName vstsagentpackage -ProfileName vstsagentpackage -ResourceGroupName vstsagentpackage -LoadContent $uploadFiles
displayName: Upload to Azure Blob
# Download all agent hashes created in previous phases
- task: DownloadBuildArtifacts@0
displayName: Download Agent Hashes
inputs:
artifactName: hash
downloadPath: $(Build.SourcesDirectory)/_hashes
# Fill release notes with agent version and package hashes
- script: |
cd release
node fillReleaseNotesTemplate.js ${{ parameters.version }}
displayName: Fill release notes
# Create agent release on Github
- powershell: |
Write-Host "Creating github release."
$releaseNotes = [System.IO.File]::ReadAllText("$(Build.SourcesDirectory)\releaseNote.md")
$releaseData = @{
tag_name = "v${{ parameters.version }}";
target_commitish = "$(Build.SourceVersion)";
name = "v${{ parameters.version }}";
body = $releaseNotes;
draft = $false;
prerelease = $true;
}
$releaseParams = @{
Uri = "https://api.github.com/repos/Microsoft/azure-pipelines-agent/releases";
Method = 'POST';
Headers = @{
Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("vsts:$(GithubToken)"));
}
ContentType = 'application/json';
Body = (ConvertTo-Json $releaseData -Compress)
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$releaseCreated = Invoke-RestMethod @releaseParams
Write-Host $releaseCreated
$releaseId = $releaseCreated.id
$assets = [System.IO.File]::ReadAllText("$(Build.SourcesDirectory)\assets.json").Replace("<AGENT_VERSION>","${{ parameters.version }}")
$assetsParams = @{
Uri = "https://uploads.github.com/repos/Microsoft/azure-pipelines-agent/releases/$releaseId/assets?name=assets.json"
Method = 'POST';
Headers = @{
Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("vsts:$(GithubToken)"));
}
ContentType = 'application/octet-stream';
Body = [system.Text.Encoding]::UTF8.GetBytes($assets)
}
Invoke-RestMethod @assetsParams
displayName: Create agent release on Github
- stage: CreatePRs
jobs:
################################################################################
- job: create_ado_prs
################################################################################
displayName: Create PRs in AzureDevOps and ConfigChange
pool:
vmImage: ubuntu-18.04
steps:
- checkout: self
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
- script: git checkout ${{ variables.releaseBranch }}
displayName: Checkout release branch
# Download all agent hashes created in previous phases
- task: DownloadBuildArtifacts@0
displayName: Download Agent Hashes
inputs:
artifactName: hash
downloadPath: $(Build.SourcesDirectory)/_hashes
- bash: |
set -x
cd release
npm install
ls
node createAdoPrs.js ${{ parameters.version }}
displayName: Create PRs in AzureDevOps and ConfigChange
env:
USERNAME: $(User)
PAT: $(AdoPAT)
USEREMAIL: $(Email)