Skip to content

Commit

Permalink
a powershell script scheduled at boot to register the runner
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaassssiiee committed Aug 19, 2021
1 parent 33d8831 commit 4c585b8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
45 changes: 30 additions & 15 deletions tasks/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
- windows_runner
- register_runner

- name: Place powershell script
win_template:
src: register.ps1
dest: C:\gitlab-runner\register.ps1
tags:
- windows_runner
- register_runner

- name: Install runner service
when: not service_info.exists
win_command: gitlab-runner.exe install
Expand All @@ -58,18 +66,25 @@
tags:
- windows_runner

- name: Register runner
win_shell: |
C:\gitlab-runner\gitlab-runner.exe register --non-interactive `
--url {{ gitlab_external_url }} `
--registration-token {{ gitlab_runner_token }} `
--description "windows-runner" `
--tag-list "windows,win32,win64" `
--locked="false" `
--executor shell
args:
chdir: C:\gitlab-runner\
ignore_errors: true
tags:
- register_runner
- windows_runner
- name: Create task to run a PS script as SYSTEM service on boot
win_scheduled_task:
name: Register
description: Register Gitlab Runner
actions:
- path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
arguments: -ExecutionPolicy Unrestricted -NonInteractive -File C:\gitlab-runner\register.ps1
triggers:
- type: boot
username: SYSTEM
run_level: highest
state: present

#- name: Register runner
# win_shell: |
# C:\gitlab-runner\register.ps1
# args:
# chdir: C:\gitlab-runner\
# ignore_errors: true
# tags:
# - register_runner
# - windows_runner
24 changes: 24 additions & 0 deletions templates/register.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<#
For the list of all environment vars run `gitlab-runner register --help`.
After registration, config.toml is generated and subsequent configuration changes should
be set in that file. Gitlab-Runner automatically picks up config.toml changes while executing.
#>

$Env:RUNNER_NAME = $env:COMPUTERNAME
$Env:REGISTRATION_TOKEN = '{{ gitlab_runner_token }}'
$Env:CI_SERVER_URL = '{{ gitlab_external_url }}'
$Env:RUNNER_TAG_LIST = 'windows,win32,win64' #comma separated list of tags

$Env:CONFIG_FILE = "$PSScriptRoot\config.toml"
$Env:REGISTER_RUN_UNTAGGED = 'false'
$Env:REGISTER_LOCKED = $false #lock runner to current project
$Env:RUNNER_EXECUTOR = 'shell'
$Env:RUNNER_SHELL = 'powershell'

$Env:RUNNER_REQUEST_CONCURRENCY = 1
$Env:RUNNER_BUILDS_DIR = ''
$Env:RUNNER_CACHE_DIR = ''


gitlab-runner register --non-interactive

0 comments on commit 4c585b8

Please sign in to comment.