英文:
"@git: not found" in Linux stage of Jenkins file
问题
我正在尝试在Linux Jenkins文件中添加阶段。并尝试从中运行git
命令,但在命令中出现错误:
错误:
@git: 未找到
感谢您的帮助
谢谢
英文:
I am trying to add stage in Linux Jenkins file. And trying to run git
command from it but getting error in command:
def tag_description = sh(script: '@git describe --tags --exact-match HEAD', returnStdout: true).trim()
Error:
@git: not found
Appreciate your help
Thanks
答案1
得分: 1
不,命令应该是 git ...
,而不是 @git
。
在 "Run bash command on jenkins pipeline" 中有更高级的 sh(script:(...)
示例,并且它们都不包含 @
。
sh label: 'Run fancy bash script',
script: '''
#!/usr/bin/env bash
echo "Hello ${SHELL}!"
'''.stripIndent().stripLeading()
或者,在 "How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?" 中:
try {
// 如果 dir1 不存在,则以非零退出状态失败
def dir1 = sh(script:'ls -la dir1', returnStdout:true).trim()
} catch (Exception ex) {
println("无法读取 dir1: ${ex}")
}
英文:
> I am running it for Linux. So is that command correct ?
No, the command should be git ...
, not @git
.
You have more advanced sh(script:(...)
examples in "Run bash command on jenkins pipeline", and none of them have a @
in them.
sh label: 'Run fancy bash script',
script: '''
#!/usr/bin/env bash
echo "Hello ${SHELL}!"
'''.stripIndent().stripLeading()
Or, as in "How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?":
try {
// Fails with non-zero exit if dir1 does not exist
def dir1 = sh(script:'ls -la dir1', returnStdout:true).trim()
} catch (Exception ex) {
println("Unable to read dir1: ${ex}")
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论