Jenkins conditional build step ${GitLastCommit}!=${GIT_COMMIT}

北城余情 提交于 2019-12-13 04:46:21

问题


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.



来源:https://stackoverflow.com/questions/33482183/jenkins-conditional-build-step-gitlastcommit-git-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!