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

Jenkins Linux阶段执行git命令报错‘@git: not found’求助

问题解决:Jenkinsfile中@git命令找不到的错误

错误原因

你在sh步骤的脚本里写了@git,shell会把@git当作完整的命令名,而系统中不存在这个命令,因此报错@git: not found。这里的@是Makefile中用来抑制命令本身打印的语法,但普通shell环境不支持该用法,不能直接加在命令前。

修复方法

直接去掉命令前的@,修改后的代码如下:

def tag_description = sh(script: 'git describe --tags --exact-match HEAD', returnStdout: true).trim()

额外说明

如果需要抑制git命令的错误输出(比如不想让"当前HEAD无对应标签"这类提示出现在Jenkins日志,但仍要获取git describe的标准输出),可以通过重定向实现:

def tag_description = sh(script: 'git describe --tags --exact-match HEAD 2>/dev/null', returnStdout: true).trim()

上述代码会将git的错误输出重定向到/dev/null,仅保留标准输出供变量获取。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 00:27:01