0

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

Digital_AI
  • 27
  • 5

1 Answers1

1

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}")
}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi @VonC, Ohk then I just need to remove "@" from it, then its correct right? – Digital_AI Jul 03 '23 at 07:13
  • @Digital_AI That is the idea, yes. – VonC Jul 03 '23 at 07:13
  • And how can I add condition before that, what is the syntax for that for ex: `iscommnet = True` – Digital_AI Jul 03 '23 at 09:44
  • @Digital_AI you can use the [shell syntax for if clauses](https://www.digitalocean.com/community/tutorials/if-else-in-shell-scripts): `def tag_description = sh(script: 'if [[ "${iscomment}" == "True" ]]; then echo "comment"; else git describe --tags --exact-match HEAD; fi', returnStdout: true).trim()` – VonC Jul 03 '23 at 09:53