Jenkins有条件的构建步骤$ {GitLastCommit}!= $ {GIT_COMMIT} [英] Jenkins conditional build step ${GitLastCommit}!=${GIT_COMMIT}

查看:1703
本文介绍了Jenkins有条件的构建步骤$ {GitLastCommit}!= $ {GIT_COMMIT}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了Jenkins服务器,因此我试图确定失败的条件构建步骤的目的:

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]

因此GIT_COMMIT的值已被填充,但GitLastCommit的未填充.

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. 对此进行检查的目的是什么?
  2. 如果我应该保留它,那么如何确保GitLastCommit获得正确的值?
  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?

推荐答案

Jenkins没有获得GitLastCommit变量的值,这就是出现上述错误的原因.

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

或者,您可以在python中运行以下命令,

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

git log --pretty="%H"

以上命令基本上给出了当前存储库的所有提交ID.

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

您可以放入一个列表(python).

You can either put in a list(python).

在python中使用os模块创建一个名为GitLastCommit的新环境变量,

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.

这篇关于Jenkins有条件的构建步骤$ {GitLastCommit}!= $ {GIT_COMMIT}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆