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

CloudBuild输出中*.sh文件被转为CRLF格式的解决问询

解决CloudBuild Drop输出中*.sh文件被转为CRLF的问题
  • 排查CloudBuild构建流程的文件处理逻辑
    检查构建脚本或cloudbuild.yaml中是否存在自动转换换行符的操作,比如部分复制工具(如xcopy)、打包工具默认会处理文本文件格式。若使用复制命令,可添加对应参数禁用换行符转换;若构建定义中有文本处理配置,需显式排除*.sh文件。

  • 修正.gitattributes规则并重新归一化文件
    替换原有规则为更明确的配置,避免规则冲突:

    * text=auto
    *.sh text eol=lf
    

    执行以下命令对整个仓库文件重新归一化,确保*.sh文件在Git仓库中以LF格式存储:

    git add --renormalize .
    git commit -m "Force LF line endings for *.sh files"
    git push origin master
    
  • 强制设置CloudBuild环境的Git配置
    构建环境可能覆盖全局Git配置,可在cloudbuild.yaml的拉取代码步骤后添加配置命令:

    steps:
      - name: 'gcr.io/cloud-builders/git'
        args: ['config', '--local', 'core.autocrlf', 'input']
      - name: 'gcr.io/cloud-builders/git'
        args: ['config', '--local', 'core.eol', 'lf']
      # 后续构建步骤...
    
  • 构建最后强制转换换行符
    若以上方法均无效,在生成Drop输出前添加步骤,将*.sh文件转换回LF格式:

    steps:
      # 前面的构建步骤...
      - name: 'gcr.io/cloud-builders/gcloud'
        entrypoint: 'bash'
        args:
          - '-c'
          - 'find ${_DROP_DIR} -name "*.sh" -type f -exec dos2unix {} \;'
        env:
          - '_DROP_DIR=/path/to/your/drop/folder'
    

    若环境无dos2unix工具,可用sed命令替代:

    find ${_DROP_DIR} -name "*.sh" -type f -exec sed -i 's/\r$//' {} \;
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 16:01:09