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; }