程式狂想筆記

一個攻城師奮鬥史

0%

Gitlab Runner 同時跑多台電腦方法

找到相關有兩個方法,參照這篇文章:如何让多个 gitlab-runner 运行同一个 tag 的 job_已解决_博问_博客园

目前沒有環境測試,看是觸發只會跑一個tag的Runner。看資料整理出來修改設定,以下試試看。

extends(兩台主機,安裝Runner,tag設定不同)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
stages:
- deploy-prod-main
- deploy-prod-sub

.deploy-prod:
msbuild:
stage: build
only:
- main
script:
- echo "Stop IIS Pool"
- $state = (Get-WebAppPoolState -Name MobileAttendanceBackend).Value
- if($state -Like "Start*") {Stop-WebAppPool -Name MobileAttendanceBackend}
- echo "Nuget restore"
- C:\MobileAttendance\Deploy\nuget.exe restore
- echo "Copy web.config"
- xcopy C:\MobileAttendance\Deploy\web.config C:\MobileAttendance\Backend\ /y
- echo "MSBuild"
- '& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\amd64\msbuild.exe" mobile-attendance-api.sln /p:platform="any cpu" /p:configuration="release" /t:mobile-attendance-api /p:OutDir=C:\MobileAttendance\Backend'
- echo "Start IIS Pool"
- C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:MobileAttendanceBackend

deploy-prod-main:
extends: .deploy-prod
tags:
- prod-main

deploy-prod-sub:
extends: .deploy-prod
tags:
- prod-sub

last-job:
stage: .post
tags:
- "MobileAttendanceVM"
only:
- main
script:
- echo "All Stages Finished."

這邊兩台主機設定不一樣tag,一台prod-main另一台prod-sub

parallel(兩台主機安裝Runner,tag設定相同)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
stages:
- build

msbuild:
stage: build
tags:
- "MobileAttendanceVM"
only:
- main
script:
- echo "Stop IIS Pool"
- $state = (Get-WebAppPoolState -Name MobileAttendanceBackend).Value
- if($state -Like "Start*") {Stop-WebAppPool -Name MobileAttendanceBackend}
- echo "Nuget restore"
- C:\MobileAttendance\Deploy\nuget.exe restore
- echo "Copy web.config"
- xcopy C:\MobileAttendance\Deploy\web.config C:\MobileAttendance\Backend\ /y
- echo "MSBuild"
- '& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\amd64\msbuild.exe" mobile-attendance-api.sln /p:platform="any cpu" /p:configuration="release" /t:mobile-attendance-api /p:OutDir=C:\MobileAttendance\Backend'
- echo "Start IIS Pool"
- C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:MobileAttendanceBackend
variables:
DEPLOY_RUNNER: ${DEPLOY_RUNNER}
parallel:
matrix:
- DEPLOY_RUNNER: [server1, server2]

last-job:
stage: .post
tags:
- "MobileAttendanceVM"
only:
- main
script:
- echo "All Stages Finished."

兩台主機Runner設定相同Tag,如:MobileAttendanceVMDEPLOY_RUNNER看說明是隨意打兩個名稱(不用對照名字),這邊寫幾個就會執行幾個Runner。

其他相關文章

使用 Gitlab CI/CD 实现自动化发布站点到 IIS - Wigor - 博客园

超简单!asp.net core前后端分离项目使用gitlab-ci持续集成到IIS_mb607022e25a607的技术博客_51CTO博客

How to setup Continuous Integration/Deployment with GitLab for ASP NET Core application

How To Set Up a Continuous Deployment Pipeline with GitLab CI/CD on Ubuntu 18.04 | DigitalOcean

如何让多个 gitlab-runner 运行同一个 tag 的 job_已解决_博问_博客园

Gitlab CI/CD 介紹與 Runner 的架設. 此篇參考[DevOps] Gitlab CI/CD 及 GitLab 的… | by Kiwi lee | Medium