0

I've inherited a Jenkins server so I'm trying to determine the purpose of a conditional build step that is failing:

enter image description here

Running the build produces this exception:

Exception caught evaluating condition: [org.jenkinsci.plugins.tokenmacro.MacroEvaluationException: Unrecognized macro 'GitLastCommit' in '${GitLastCommit}!=e2859cd109f46e889da99391f149ea68c20b1c75'], action = [Don't run]

So the value of GIT_COMMIT is being filled but GitLastCommit is not being filled.

Since it doesn't work I'm wondering how to proceed.

  1. What's the purpose of checking for this?
  2. If I should keep it then how to I ensure that GitLastCommit gets the right value?
kraftydevil
  • 5,144
  • 6
  • 43
  • 65
  • You can inject an environment variable GitLastCommit and assign the required value at the beginning. – Harish Talanki Nov 02 '15 at 16:45
  • Yes that's true but I'm not sure what the value should be. – kraftydevil Nov 02 '15 at 16:53
  • 1
    Then you cannot use this..!!! Alternatively, what you can do is run a python/perl script in the pre-build process, which fetches the last but one commit id from the repository and create an environment variable GitLastCommit and assign the value. So, when this step runs, it will have the value. – Harish Talanki Nov 02 '15 at 16:56
  • I'll probably remove this condition for now and keep investigating where the value is supposed to come from – kraftydevil Nov 02 '15 at 17:15

1 Answers1

0

Jenkins did not get the value for GitLastCommit variable and that is the reason you got the above error.

Alternatively what you can to do is run the below command in python,

git log --pretty="%H"

the above command basically gives all the commit id's of the current repository.

You can either put in a list(python).

Use the os module in python to create a new environment variable called GitLastCommit,

os.environ["GitLastCommit"] = <<Assign the required value from the list depending on your requirement>> 

And then inject this environment variable so that you can use this value else where.

Harish Talanki
  • 866
  • 13
  • 27