Skip to content

Commit 2706c09

Browse files
authored
feat: Request new Runner token if invalid (#425)
* Request new Runner token if invalid * Escape the "%{" sequence * Fix template error accessing variables
1 parent 36633fa commit 2706c09

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

template/gitlab-runner.tpl

+10-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ if ! [ -x "$(command -v jq)" ]; then
5858
yum install jq -y
5959
fi
6060

61+
# fetch Runner token from SSM and validate it
6162
token=$(aws ssm get-parameters --names "${secure_parameter_store_runner_token_key}" --with-decryption --region "${secure_parameter_store_region}" | jq -r ".Parameters | .[0] | .Value")
62-
if [[ `echo ${runners_token}` == "__REPLACED_BY_USER_DATA__" && `echo $token` == "null" ]]
63+
64+
valid_token=true
65+
if [[ `echo $token` != "null" ]]
66+
then
67+
valid_token_response=$(curl -s -o /dev/null -w "%%{response_code}" --request POST -L "${runners_gitlab_url}/api/v4/runners/verify" --form "token=$token" )
68+
[[ `echo $valid_token_response` != "200" ]] && valid_token=false
69+
fi
70+
71+
if [[ `echo ${runners_token}` == "__REPLACED_BY_USER_DATA__" && `echo $token` == "null" ]] || [[ `echo $valid_token` == "false" ]]
6372
then
6473
token=$(curl --request POST -L "${runners_gitlab_url}/api/v4/runners" \
6574
--form "token=${gitlab_runner_registration_token}" \

0 commit comments

Comments
 (0)