-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.ps1
More file actions
72 lines (54 loc) · 2.2 KB
/
deploy.ps1
File metadata and controls
72 lines (54 loc) · 2.2 KB
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
$token = $env:api_token
$accountName = $env:appveyor_account_name
$projectSlug = $env:deploy_project
$buildVersion = $env:deploy_version
$downloadLocation = $env:appveyor_build_folder
$deployArtifact = $env:deploy_artifact
$apiUrl = 'https://ci.appveyor.com/api'
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
# get project with last build details
if($buildVersion) {
$buildUrl = "$apiUrl/projects/$accountName/$projectSlug/build/$buildVersion"
} else {
Write-Host "Deploying the most recent build"
$buildUrl = "$apiUrl/projects/$accountName/$projectSlug"
}
$project = Invoke-RestMethod -Method Get -Uri $buildUrl -Headers $headers
Write-Host "Project: $($project.project.name)"
Write-Host "Build: $($project.build.version)"
# we assume here that build has a single job
# get this job id
$jobId = $project.build.jobs[0].jobId
# get job artifacts (just to see what we've got)
$artifacts = Invoke-RestMethod -Method Get -Uri "$apiUrl/buildjobs/$jobId/artifacts" -Headers $headers
if($artifacts.Length -eq 0) {
Write-Host "Build does not contain artifacts" -ForegroundColor Yellow
return
}
$artifactsDownloaded = 0
# download all artifacts
for($i = 0; $i -lt $artifacts.length; $i++) {
# filter artifacts if specified
if($deployArtifact -and -not ($artifacts[$i].fileName -eq $deployArtifact -or $artifacts[$i].name -eq $deployArtifact)) {
continue
}
if($artifactsDownloaded -eq 0) {
Write-Host "Downloading build artifacts"
}
$artifactFileName = [IO.Path]::GetFileName($artifacts[$i].fileName)
Write-Host "[$($i + 1) of $($artifacts.length)] $artifactFileName -> `$env:appveyor_build_folder\$artifactFileName" -ForegroundColor Gray
# artifact will be downloaded as
$localArtifactPath = "$downloadLocation\$artifactFileName"
# download artifact
# -OutFile - is local file name where artifact will be downloaded into
Invoke-RestMethod -Method Get -Uri "$apiUrl/buildjobs/$jobId/artifacts/$artifactFileName" `
-OutFile $localArtifactPath -Headers $headers
$artifactsDownloaded++
}
if($artifactsDownloaded -eq 0) {
Write-Host "No artifacts were downloaded" -ForegroundColor Yellow
return
}