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

Ubuntu下Jenkins Pipeline构建.NET Core时系统挂起问题求助

问题:1核1GB内存VPS上Jenkins执行dotnet build时系统挂起

环境信息

  • 服务器配置:1核CPU、1GB内存、21GB SSD
  • 操作系统:Ubuntu 22.04.4 LTS
  • 部署框架:.NET Core 8.0
  • CI工具:Jenkins

Jenkins Pipeline脚本

agent any
stages {
    stage('Cloning Git') {
         steps {
            checkout([$class: 'GitSCM', branches: [[name: '*/main']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '.....................', url: 'https://.........@gitlab.com/../......']]])
        }
    }
     stage('Build Stage') {
        steps {
            echo 'start build'
            sh """
            cd FacilityManagementWebClient
            dotnet build -c Release /p:Version=1
            dotnet publish -c Release --no-build
            """
            echo 'end build'
        }
    }
}

任务错误日志

wrapper script does not seem to be touching the log file in /var/lib/jenkins/workspace/Deploy-Pipeline@tmp/durable-f29751e5

 (JENKINS-48300: if on an extremely laggy filesystem, consider - 
Dorg.jenkinsci.plugins.durabletask. 
BourneShellScript.HEARTBEAT_CHECK_INTERVAL=86400)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code -1
Finished: FAILURE

解决方法

1. 缓解内存不足问题

1GB内存不足以支撑.NET Core 8.0的编译过程,编译时内存耗尽会导致系统无响应,触发Jenkins心跳超时。

  • 临时方案:创建1GB交换分区
    sudo fallocate -l 1G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    
  • 永久生效:编辑/etc/fstab,添加一行/swapfile none swap sw 0 0,重启服务器后自动挂载。

2. 优化dotnet编译参数

减少编译时的资源占用:

  • 限制并行编译任务数:修改build命令为
    dotnet build -c Release /p:Version=1 /p:NumberOfProcessors=1
  • 禁用共享编译:添加参数/p:UseSharedCompilation=false,减少内存开销

3. 调整Jenkins心跳检测间隔

根据错误提示,延长Jenkins的心跳检测时间:

  • 编辑Jenkins启动配置文件(如/etc/default/jenkins),在JAVA_ARGS后添加:
    -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=86400
  • 重启Jenkins服务:sudo systemctl restart jenkins

4. 清理工作空间缓存

旧编译缓存可能占用资源,在Pipeline中添加清理步骤:

stage('Clean Workspace') {
    steps {
        cleanWs()
    }
}

内容的提问来源于stack exchange,提问作者Hậu tran

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 03:12:19