gitlab-runner的配置
concurrent = 1 check_interval = 0 [session_server] session_timeout = 1800 [[runners]] name = "yourname" url = "https://git.yourname.com/" token = "yourtoken" executor = "shell" shell = "powershell" [runners.custom_build_dir] [runners.cache] [runners.cache.s3] [runners.cache.gcs]
.gitlab-ci.yml文件
Job: stage: deploy only: ["yourname"] tags: ["yourtag"] script: - chcp 65001 - echo "spend my 10 hours" - "C:" - cd C:\www\ - git pull
說明:
gitlab-runner運行在linux下時,運行良好,但在windows下卻出問題。
最嚴重的問題是.gitlab-ci.yml配置內的git無法運行。但在windows服務器內直接測試是可以運行的。
最后只好寫個windows的bat:
@echo off title git pull.bat set WORK_DIR=%~dp0 echo Switch to %WORK_DIR% cd /d %WORK_DIR% set INTERVAL=20 timeout %INTERVAL% :Again git pull timeout %INTERVAL% goto Again
一執行,還是不行。報錯。原來:
當您使用"以管理員身份運行"選項運行在 Windows Vista 中,或在 Windows Server 2008 中使用環境變量的應用程序時,您會遇到各種錯誤在 Windows Vista 和 Windows Server 2008 中,環境變量的值的長度被限制為 2048 個字符。但是,通過使用以管理員身份運行選項運行的應用程序通過使用環境變量時,環境變量的值被截斷為 1024 個字符的長度
本段原文鏈接:https://blog.csdn.net/godenlove007/article/details/8257132
最后是用這個辦法:
https://blog.csdn.net/github_34777264/article/details/85342877
修改了環境變量。
果然,bat文件可以正常執行了。
再次嘗試gitlab-runner下的git pull。然而並沒有什么卵用。
最后不斷的思考。沒道理linux下很正常。windows下就行啊。
想到是用戶權限問題,於是通過在gitlab-ci.yml中執行
whoami
發現用戶是system用戶。不存在權限問題。
又考慮了一下。有可能是沒有gitlab的倉庫的權限。於是執行了這句:
git config --global credential.helper store
成功。
參考的powershell
if (Test-Path C:\www\site) { cd C:\wwwroot\site; git status; git pull; }
