@@ -5,25 +5,25 @@ $Token = (Invoke-WebRequest -UseBasicParsing -Method Put -Headers @{'X-aws-ec2-m
5
5
$InstanceId = (Invoke-WebRequest - UseBasicParsing - Headers @ {' X-aws-ec2-metadata-token' = $Token } http:// 169.254 .169.254 / latest/ meta- data/ instance- id).content
6
6
$Region = (Invoke-WebRequest - UseBasicParsing - Headers @ {' X-aws-ec2-metadata-token' = $Token } http:// 169.254 .169.254 / latest/ meta- data/ placement/ region).content
7
7
8
- Write-Output " terminate-instance: requesting instance termination..."
8
+ Write-Output " $ ( Get-Date ) terminate-instance: requesting instance termination..."
9
9
aws autoscaling terminate- instance- in- auto- scaling- group -- region " $Region " -- instance- id " $InstanceId " " --should-decrement-desired-capacity" 2> $null
10
10
11
11
# If autoscaling request was successful, we will terminate the instance, otherwise, if
12
12
# BuildkiteTerminateInstanceAfterJob is set to true, we will mark the instance as unhealthy
13
13
# so that the ASG will terminate it despite scale-in protection. Otherwise, we should not
14
14
# terminate the instance, so we need to retart the agent.
15
15
if ($lastexitcode -eq 0 ) {
16
- Write-Output " terminate-instance: terminating instance..."
16
+ Write-Output " $ ( Get-Date ) terminate-instance: terminating instance..."
17
17
} else {
18
- Write-Output " terminate-instance: ASG could not decrement (we're already at minSize)"
18
+ Write-Output " $ ( Get-Date ) terminate-instance: ASG could not decrement (we're already at minSize)"
19
19
if ($Env: BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB -eq " true" ) {
20
- Write-Output " terminate-instance: marking instance as unhealthy"
20
+ Write-Output " $ ( Get-Date ) terminate-instance: marking instance as unhealthy"
21
21
aws autoscaling set-instance - health `
22
22
-- instance- id " $InstanceId " `
23
23
-- region " $Region " `
24
24
-- health- status Unhealthy
25
25
} else {
26
- Write-Output " terminate-instance: restarting agent..."
26
+ Write-Output " $ ( Get-Date ) terminate-instance: restarting agent..."
27
27
nssm start buildkite- agent
28
28
}
29
29
}
0 commit comments