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

Rundeck Windows节点Git Clone误报错误的解决咨询

Rundeck WinRM节点Git Clone成功却返回非零结果码误报的解决方法

问题场景

在搭载WinRM插件的Rundeck Windows 11 Pro节点上,执行内联脚本时出现异常:Git Clone命令已成功拉取代码仓库,但Rundeck返回非零结果码误报错误;而执行Git Init命令时输出和结果均正常。

执行的内联脚本

mkdir C:\Users\peter\CodeBase
cd C:\Users\peter\CodeBase
fsutil.exe file SetCaseSensitiveInfo "C:\Users\peter\CodeBase" enable
git  clone https://github.com/scothost/AspBlog.git AspBlog 

错误输出

Case sensitive attribute on directory C:\Users\peter\CodeBase is enabled.
C:\Users\peter\CodeBase>git  clone https://github.com/scothost/AspBlog.git AspBlog  
[ERROR  ]  Execution finished with the following error (winrm-exec.py:378)[root]
[ERROR  ]  Cloning into 'AspBlog'...
 (winrm-exec.py:379)[root]
Failed: NonZeroResultCode: [WinRMPython] Result code: 1

正常执行的Git Init脚本及输出

脚本:

mkdir C:\Users\peter\CodeBase
cd C:\Users\peter\CodeBase
fsutil.exe file SetCaseSensitiveInfo "C:\Users\peter\CodeBase" enable
git init

输出:

Case sensitive attribute on directory C:\Users\peter\CodeBase is enabled.
C:\Users\peter\CodeBase>git init 
Initialized empty Git repository in C:/Users/peter/CodeBase/.git/

解决方法

1. 强制修正退出码

Git Clone可能因输出流识别问题返回非零码但实际执行成功,可在脚本末尾手动指定成功退出码:

mkdir C:\Users\peter\CodeBase
cd C:\Users\peter\CodeBase
fsutil.exe file SetCaseSensitiveInfo "C:\Users\peter\CodeBase" enable
git clone https://github.com/scothost/AspBlog.git AspBlog || exit 0

更稳妥的方式是通过检查仓库目录是否存在来判断执行结果:

mkdir C:\Users\peter\CodeBase
cd C:\Users\peter\CodeBase
fsutil.exe file SetCaseSensitiveInfo "C:\Users\peter\CodeBase" enable
git clone https://github.com/scothost/AspBlog.git AspBlog
if exist "C:\Users\peter\CodeBase\AspBlog\.git" (exit 0) else (exit 1)

2. 重定向Git输出流

Git Clone可能将正常日志输出到stderr,导致WinRM插件误判,可将stderr重定向到stdout:

mkdir C:\Users\peter\CodeBase
cd C:\Users\peter\CodeBase
fsutil.exe file SetCaseSensitiveInfo "C:\Users\peter\CodeBase" enable
git clone https://github.com/scothost/AspBlog.git AspBlog 2>&1

3. 使用Git完整路径调用

避免因环境变量问题导致Git执行异常,直接使用Git的完整路径:

mkdir C:\Users\peter\CodeBase
cd C:\Users\peter\CodeBase
fsutil.exe file SetCaseSensitiveInfo "C:\Users\peter\CodeBase" enable
"C:\Program Files\Git\bin\git.exe" clone https://github.com/scothost/AspBlog.git AspBlog

4. 调整Rundeck作业设置

在Rundeck作业的步骤配置中:

  • 开启「忽略错误输出」选项,避免正常日志被误判为错误
  • 自定义结果码规则,将结果码1标记为成功状态

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 14:50:06