GitLab构建.NET Core 7 MVC应用时Artifacts未找到问题排查
解决GitLab构建.NET Core 7 MVC应用时的Artifacts路径警告问题
问题原因
GitLab CI的artifacts.paths要求使用相对于当前工作目录的路径,你配置的$CI_PROJECT_DIR/bin/Release/net7.0是绝对路径,相当于在工作目录(/builds/xmoor/Xmoor-Payroll-Management)下重复查找完整绝对路径,自然找不到匹配文件。
解决方案
1. 修正Artifacts路径为相对路径
将artifacts.paths中的绝对路径改为相对路径,去掉$CI_PROJECT_DIR前缀:
build: stage: build image: mcr.microsoft.com/dotnet/sdk:7.0 script: - dotnet build $solution --configuration Release --no-restore artifacts: paths: - bin/Release/net7.0
2. 验证Build输出路径是否正确
如果修改路径后仍有问题,可在脚本中添加目录检查命令,确认编译后的文件是否生成在预期位置:
build: stage: build image: mcr.microsoft.com/dotnet/sdk:7.0 script: - dotnet build $solution --configuration Release --no-restore # 查看编译输出目录的文件结构 - ls -la bin/Release/net7.0 # 查找指定目录下的编译产物 - find . -name "*.dll" -path "*bin/Release/net7.0*" artifacts: paths: - bin/Release/net7.0
3. 确认$solution变量的正确性
确保$solution变量指向正确的项目或解决方案文件,若变量未正确定义,可直接写死路径避免问题:
script: - dotnet build Xmoor-Payroll-Management.sln --configuration Release --no-restore
内容的提问来源于stack exchange,提问作者kanishka
相关产品推荐
相关产品推荐

