在Jenkins文件的Linux阶段中出现了”@git: not found”错误。

huangapple go评论62阅读模式
英文:

"@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}")
}

huangapple
  • 本文由 发表于 2023年7月3日 14:05:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602195.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定