-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHue_runner.ps1
108 lines (94 loc) · 2.24 KB
/
Hue_runner.ps1
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
param(
[Alias("ju")]
$UserID,
[Alias("jp")]
$Passwor ,
[Alias("j")]
$JenkinsUrl,
[Alias("l")]
$LightsUrl ,
[Alias("f")]
[int]
$Failed = 0,
[Alias("w")]
[int]
$FailedBuilding = 12750,
[Alias("b")]
[int]
$Building = 46920,
[Alias("p")]
[int]
$Passed = 25717,
[alias("u")]
[int]
$Unstable = 6000,
[Alias("r")]
[int]
$Brightness = 10,
[Alias("s")]
[int]
$Saturation = 255
)
function Get-Basic-Auth {
$Key = $UserID + ":" + $Password
$authVal = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($key))
return @{"AUTHORIZATION"=$authVal}
}
function Set-Color ($color){
$hash = @{ hue = $color; bri = $Brightness; sat = $Saturation}
$json = $hash | convertto-json
$result = Invoke-WebRequest -uri $LightsUrl -Method PUT -Body $json
}
function Has-Status ($json, $status){
for($i=0; $i -lt $json.jobs.length; $i++){
if(($json.jobs[$i].color -eq $status) -or ($status.StartsWith("_") -and $json.jobs[$i].color.Contains($status) )){
return $true
}
}
return $false
}
function Get-Jenkins-Status {
$Auth = Get-Basic-Auth
$response = Invoke-WebRequest -Uri $JenkinsUrl -Headers $Auth
Write-Host $response.Content
return $response.Content | ConvertFrom-Json
}
function Is-Building ($json){
return Has-Status $json "_anime"
}
function Has-Failure($json){
return Has-Status $json "red" -or Has-Status $json "red_anime"
}
function Has-Unstable($json){
return Has-Status $json "yellow" -or Has-Status $json "yellow_anime"
}
function Is-Passed($json){
$hasFailure = Has-Failure $json
$hasUnstable = Has-Unstable $json
return !$hasFailure -and !$hasUnstable
}
$json = Get-Jenkins-Status
if( Is-Building $json ){
if(Has-Failure $json ){
Write-Host "Is Building Has Failure"
Set-Color $FailedBuilding
}
else{
Write-Host "Is Building"
Set-Color $Building
}
}
else{
if(Has-Failure $json ){
Write-Host "Has Failure"
Set-Color $Failed
}
elseif(Has-Unstable $json ) {
Write-Host "The Build is Unstable"
Set-Color $Unstable
}
elseif(Is-Passed $json ){
Write-Host "Build Has Passed"
Set-Color $Passed
}
}