Skip to content
Snippets Groups Projects
Commit 00ec29dc authored by jurgenhaas's avatar jurgenhaas
Browse files

Add support for auto-registration of runners

parent cd9e586f
No related branches found
No related tags found
No related merge requests found
......@@ -63,4 +63,12 @@
tags:
- cron
- name: Auto-register runners for projects
cron:
name: Auto-register runners
job: /usr/local/bin/register-gitlab-runner auto > /dev/null 2>&1 && {{ lookup('healthchecks', '', user='root', jobname='Auto-register runners', schedule='* * * * *', disabled=crons_disabled|default(false)) }}
disabled: '{{ crons_disabled|default(false) }}'
tags:
- cron
when: not excluded_roles or "gitlab-runner" not in excluded_roles
#!/bin/bash
set -e
if [[ "$1" == "" ]]; then
echo "Project ID required as first argument."
exit 1
elif [[ "$1" == "auto" ]]; then
ID=$(curl -s -H "PRIVATE-TOKEN: {{ gitlab_issue.token }}" "https://gitlab.lakedrops.com/api/v4/projects/?topic=needs_runner_{{ inventory_hostname }}" | jq -r '.[0].id')
if [[ "$ID" == "null" ]]; then
echo "Nothing to do"
exit 0
fi
echo "Adding runner for project ID $ID"
curl -X PUT -s -H "PRIVATE-TOKEN: {{ gitlab_issue.token }}" "https://gitlab.lakedrops.com/api/v4/projects/${ID}" -d "topics=runner_{{ inventory_hostname }}"
else
ID=$1
fi
ID=$1
TOKEN=$(curl -s -H "PRIVATE-TOKEN: {{ gitlab_issue.token }}" "https://gitlab.lakedrops.com/api/v4/projects/${ID}" | jq -r .runners_token)
NAME=$(curl -s -H "PRIVATE-TOKEN: {{ gitlab_issue.token }}" "https://gitlab.lakedrops.com/api/v4/projects/${ID}" | jq -r .path_with_namespace)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment