0

In "Manage Jenkins" -> "Configure System" -> "Global properties", I added:

Name:  git
Value: /path/to/my/git

and:

Name: PATH+git
Value: /path/to/my/git

However, if I try sh("git status") from a Jenkins pipeline, I get:

git: command not found

While if I try with the full path sh("/path/to/my/git status"), git is seen.

Any idea why git is not seen in a Jenkins Pipeline Script after being declared as an environment variable?

bsky
  • 19,326
  • 49
  • 155
  • 270

1 Answers1

1

You have to use variable reference in your sh step:

sh '$git status'

Note the single quotes, this is so that groovy doesn't interpret the $ as an variable reference (leave it up to sh). If you use double quotes, then you have to escape the dollar sign:

sh "\$git status"

or you can access the environment directly in groovy:

sh "${env.git} status"
Jon S
  • 15,846
  • 4
  • 44
  • 45
  • Is there a way to make `git`be seen as the environment variable? There is a script that calls `git` directly, which I can not modify. – bsky Mar 06 '17 at 16:53
  • 2
    I would suggest that you modify the PATH variable and append your path to git at the **start** of the path variable, e.g. `/path/to/my/git:$PATH`. See this answer: http://stackoverflow.com/a/5819768/7509826 – Jon S Mar 06 '17 at 16:57