You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure容器实例中Jenkins构建.NET 8.0应用失败求助

解决Azure容器实例中Jenkins构建.NET 8应用的ICU缺失问题

问题描述

在Azure容器实例中运行Jenkins,构建.NET 8.0应用时触发ICU包缺失错误。已在项目文件中添加<InvariantGlobalization>true</InvariantGlobalization>但问题未解决;尝试执行apt-get install libicu-dev安装依赖时,因权限不足失败,且容器内未预装sudo。

完整错误日志:

Process terminated. Couldn't find a valid ICU package installed on the system. Please install libicu (or icu-libs) using your package manager and try again. Alternatively you can set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support. Please see https://aka.ms/dotnet-missing-libicu for more information.
at System.Environment.FailFast(System.String)
at System.Globalization.GlobalizationMode+Settings..cctor()
at System.Globalization.CultureData.CreateCultureWithInvariantData()
at System.Globalization.CultureData.get_Invariant()
at System.Globalization.TextInfo..cctor()
at System.String.ToLowerInvariant()
at System.Text.EncodingHelper.GetEncodingFromCharset()
at System.ConsolePal.GetConsoleEncoding()
at System.Console.get_OutputEncoding()
at Microsoft.DotNet.Cli.AutomaticEncodingRestorer..ctor()
at Microsoft.DotNet.Cli.Program.Main(System.String[])
.NET Command Completed - Exit Code: 134
ERROR: Command execution completed with return code 134.
Finished: FAILURE

解决方案

方案1:全局启用不变全球化模式

项目文件中的<InvariantGlobalization>配置可能未覆盖dotnet命令启动阶段的依赖检查,需在Jenkins构建流程中全局设置环境变量:

  • 在Jenkins构建步骤的shell命令开头添加:
    export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
    
  • 或者在Jenkins的「全局工具配置」或「项目环境变量」中直接添加DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true,确保所有dotnet命令执行时生效。

方案2:构建预安装libicu的自定义Jenkins镜像

直接在运行中的容器内安装依赖因权限受限无法操作,需自定义镜像并重新部署到Azure容器实例:

  1. 创建Dockerfile:
    FROM jenkins/jenkins:lts
    USER root
    RUN apt-get update && apt-get install -y libicu-dev
    USER jenkins
    
  2. 构建镜像并推送到Azure容器注册表(ACR):
    docker build -t your-acr-name.azurecr.io/jenkins-with-libicu:lts .
    docker push your-acr-name.azurecr.io/jenkins-with-libicu:lts
    
  3. 更新Azure容器实例的镜像配置,使用上述自定义镜像重新部署。

方案3:临时以root用户运行容器(不推荐用于生产)

若仅需临时测试,可修改Azure容器实例的运行用户为root:

  • 在Azure门户的容器实例配置中,找到「高级」设置,将运行用户设置为root
  • 重新启动容器后,执行apt-get update && apt-get install -y libicu-dev即可完成安装

内容的提问来源于stack exchange,提问作者Ivan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 13:25:53