摘要
在Gitlab的作业日志中,执行PowerShell语句后的输出是乱码。即使是英文也是乱码。
网上搜索到的结果
下属两种做法,在Windows 11中都是无效的:
乱码的效果:
$ echo $MSBUILD
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\
$ cd $MSBUILD
$ msbuild.exe "Daiv_OA.Web\Daiv_OA.Web.csproj" -o $DAIV_OA_WEB_OUTPUT_DIR
msbuild.exe : ������msbuild.exe����ʶ��Ϊ cmdlet���������ű��ļ��������г��������ơ����������Ƶ�ƴд����������·������ȷ��·����ȷ��Ȼ������һ�Ρ�
����λ�� ��:297 �ַ�: 1
+ msbuild.exe "Daiv_OA.Web\Daiv_OA.Web.csproj" -o $DAIV_OA_WEB_OUTPUT_D ...
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (msbuild.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
1、在.gitlab-ci.yml中设置
build-job:
stage: build
tags:
- zhongfang-windows
before_script:
- chcp.com 65001 # 加入这一行
script:
- echo "Compiling the code..."
2、在Gitlab Runner的config.toml中设置
concurrent = 1
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Alice-WIndows-11"
url = "https://gitlab.********.cn"
id = 37
token = "****-************************"
token_obtained_at = 2024-04-11T16:39:42Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "shell"
shell = "powershell"
pre_clone_script = "chcp 65001" # 加入这两行
pre_build_script = "chcp 65001"
[runners.cache]
MaxUploadedArchiveSize = 0
正确做法
正确的输出
$ echo $MSBUILD
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\
$ cd $MSBUILD
$ msbuild "Daiv_OA.Web\Daiv_OA.Web.csproj" -o $DAIV_OA_WEB_OUTPUT_DIR
msbuild : The term 'msbuild' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path
is correct and try again.
At line:297 char:1
+ msbuild "Daiv_OA.Web\Daiv_OA.Web.csproj" -o $DAIV_OA_WEB_OUTPUT_DIR
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (msbuild:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
继续去摸索下一个坑:这里明明有msbuild.exe,为什么就用不了呢?
黑夜里不停折腾的代码行者。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 精选 4 款免费且实用的数据库管理工具,程序员必备!
· 干货分享!MCP 实现原理,小白也能看懂
· Cursor:一个让程序员“失业”的AI代码搭子
· MCP开发应用,使用python部署sse模式
· 慢查询解决思路