File tree Expand file tree Collapse file tree 4 files changed +19
-9
lines changed
windows/conf/buildkite-agent/scripts Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,13 @@ on_error() {
11
11
local exitCode=" $? "
12
12
local errorLine=" $1 "
13
13
14
+ # If the curl fails, we're already in the error trap...
15
+ # shellcheck disable=SC2155
16
+ local token=$( curl -X PUT -H " X-aws-ec2-metadata-token-ttl-seconds: 60" --fail --silent --show-error --location " http://169.254.169.254/latest/api/token" )
17
+
14
18
if [[ $exitCode != 0 ]] ; then
15
- TOKEN=$( curl -X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 60" )
16
19
aws autoscaling set-instance-health \
17
- --instance-id " $( curl -H " X-aws-ec2-metadata-token: $TOKEN " http://169.254.169.254/latest/meta-data/instance-id) " \
20
+ --instance-id " $( curl -H " X-aws-ec2-metadata-token: $token " --fail --silent --show-error --location " http://169.254.169.254/latest/meta-data/instance-id" ) " \
18
21
--health-status Unhealthy || true
19
22
fi
20
23
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ echo "sleeping for 10 seconds before terminating instance to allow agent logs to
6
6
7
7
sleep 10
8
8
9
- TOKEN =$( curl -X PUT " http://169.254.169.254/latest/api/token " -H " X-aws-ec2-metadata-token-ttl-seconds: 60" )
10
- instance_id=$( curl -H " X-aws-ec2-metadata-token: $TOKEN " -fsSL http://169.254.169.254/latest/meta-data/instance-id)
11
- region=$( curl -H " X-aws-ec2-metadata-token: $TOKEN " -fsSL http://169.254.169.254/latest/meta-data/placement/availability-zone | head -c -1 )
9
+ token =$( curl -X PUT -H " X-aws-ec2-metadata-token-ttl-seconds: 60" --fail --silent --show-error --location " http://169.254.169.254/latest/api/token " )
10
+ instance_id=$( curl -H " X-aws-ec2-metadata-token: $token " --fail --silent --show-error --location " http://169.254.169.254/latest/meta-data/instance-id" )
11
+ region=$( curl -H " X-aws-ec2-metadata-token: $token " --fail --silent --show-error --location " http://169.254.169.254/latest/meta-data/placement/region " )
12
12
13
13
echo " requesting instance termination..."
14
14
Original file line number Diff line number Diff line change @@ -14,9 +14,16 @@ mark_instance_unhealthy() {
14
14
# mark the instance for termination
15
15
echo " Marking instance as unhealthy"
16
16
17
- TOKEN=$( curl -X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 60" )
17
+ # shellcheck disable=SC2155
18
+ local token=$( curl -X PUT -H " X-aws-ec2-metadata-token-ttl-seconds: 60" --fail --silent --show-error --location " http://169.254.169.254/latest/api/token" )
19
+ # shellcheck disable=SC2155
20
+ local instance_id=$( curl -H " X-aws-ec2-metadata-token: $token " --fail --silent --show-error --location " http://169.254.169.254/latest/meta-data/instance-id" )
21
+ # shellcheck disable=SC2155
22
+ local region=$( curl -H " X-aws-ec2-metadata-token: $token " --fail --silent --show-error --location " http://169.254.169.254/latest/meta-data/placement/region" )
23
+
18
24
aws autoscaling set-instance-health \
19
- --instance-id " $( curl -H " X-aws-ec2-metadata-token: $TOKEN " http://169.254.169.254/latest/meta-data/instance-id) " \
25
+ --instance-id " ${instance_id} " \
26
+ --region " ${region} " \
20
27
--health-status Unhealthy
21
28
}
22
29
@@ -32,7 +39,7 @@ if ! /usr/local/bin/bk-check-disk-space.sh ; then
32
39
docker builder prune --all --force --filter " until=${DOCKER_PRUNE_UNTIL} "
33
40
34
41
if ! /usr/local/bin/bk-check-disk-space.sh ; then
35
- echo " Disk health checks failed" >&2
42
+ echo " Disk health checks failed" >&2 && false
36
43
exit 1
37
44
fi
38
45
fi
Original file line number Diff line number Diff line change 1
1
$Token = (Invoke-WebRequest - UseBasicParsing - Method Put - Headers @ {' X-aws-ec2-metadata-token-ttl-seconds' = ' 60' } http:// 169.254 .169.254 / latest/ api/ token).content
2
2
3
3
$InstanceId = (Invoke-WebRequest - UseBasicParsing - Headers @ {' X-aws-ec2-metadata-token' = $Token } http:// 169.254 .169.254 / latest/ meta- data/ instance- id).content
4
- $Region = (Invoke-WebRequest - UseBasicParsing - Headers @ {' X-aws-ec2-metadata-token' = $Token } http:// 169.254 .169.254 / latest/ meta- data/ placement/ availability - zone ).content -replace " .$ "
4
+ $Region = (Invoke-WebRequest - UseBasicParsing - Headers @ {' X-aws-ec2-metadata-token' = $Token } http:// 169.254 .169.254 / latest/ meta- data/ placement/ region ).content
5
5
6
6
Write-Output " terminate-instance: requesting instance termination..."
7
7
aws autoscaling terminate- instance- in- auto- scaling- group -- region " $Region " -- instance- id " $InstanceId " " --should-decrement-desired-capacity" 2> $null
You can’t perform that action at this time.
0 commit comments