-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAzure_Devops_Repository_Build_Status.ps1
More file actions
70 lines (55 loc) · 2.17 KB
/
Azure_Devops_Repository_Build_Status.ps1
File metadata and controls
70 lines (55 loc) · 2.17 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
Write-Host "Start"
$personalToken = "<TOKEN>"
$projectURL = "https://dev.azure.com/<PROJECT_NAMEE>/_apis/"
$host.SetShouldExit($exitcode)
exit
}
function GetBuildStatus(){
param(
[string]$target_repo
)
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
$header = @{authorization = "Basic $token"}
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "PAT", $personalToken)))
$headers = @{
Authorization = "Basic $($base64AuthInfo)"
}
Write-Host "Get module definition " $target_repo
$relDefUrl = $projectURL+"/build/definitions?api-version=5.0"
$result = Invoke-RestMethod $relDefUrl -Method Get -ContentType "application/json" -Headers $header
$relDefs = $result.value
if($relDefs.count -gt 0){
#Write-Host "$project $($relDefs.count) build def founds" -ForegroundColor Red
$relDefs | ForEach-Object {
if ($_.name -eq $target_repo)
{
Write-host "name = $($_.name)"
$definition_obj= $($_)
}
}
}
Write-Host "Get build definition according with the module"
$definition_id=$definition_obj.id
$relDefUrl = $projectURL+"/build/builds?definitions="+$definition_id+"&api-version=5.0"
$result = Invoke-RestMethod $relDefUrl -Method Get -ContentType "application/json" -Headers $header
$relDefs = $result.value
$check_st=0
$curr_build_num=0
if($relDefs.count -gt 0){
$lastBuild = $relDefs[0]
$curr_build_num=$lastBuild.id
$last_build_status = $lastBuild.result
Write-host "last built id = "$curr_build_num
Write-host "last built status = "$last_build_status -ForegroundColor Green
if (!$last_build_status -eq "succeeded" -or $last_build_status -eq "")
{
Write-host "Detected build error!" -ForegroundColor Red
}
}
}
#Getting CI-HelloWorld build status
$target_repo="CI-HelloWorld"
Write-Host "Module Name " $target_repo
GetBuildStatus $target_repo
Write-Host "*******************************************************************************"
a