Jenkins conditional build step ${GitLastCommit}!=$

2019-09-11 11:40发布

问题:

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

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?

回答1:

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.