我目前正在使用 Jenkins 建立一个持续集成系统,但遇到了一个问题:
几乎每个项目都依赖于其他项目。因此,为了执行日常构建,我使用CloudBees Build Flow 插件。它实际上做得很好,但不是以最佳方式:它构建了我告诉它的每一个工作,甚至没有检查 Git 是否有任何变化。所以我想知道是否有任何方法可以强制 Jenkins 在实际构建项目之前检查 Git 是否有任何更改。
PS:对不起我的英语,我不是母语人士
我目前正在使用 Jenkins 建立一个持续集成系统,但遇到了一个问题:
几乎每个项目都依赖于其他项目。因此,为了执行日常构建,我使用CloudBees Build Flow 插件。它实际上做得很好,但不是以最佳方式:它构建了我告诉它的每一个工作,甚至没有检查 Git 是否有任何变化。所以我想知道是否有任何方法可以强制 Jenkins 在实际构建项目之前检查 Git 是否有任何更改。
PS:对不起我的英语,我不是母语人士
最后,我选择坚持使用 BuildFlow 和 Groovy 语言,而不是使用脚本,但这只是为了方便,而且这个解决方案完全可以使用 shell 语言。此外,使用 BuildFlow 允许您使用 Parallel(),同时启动多个作业。
这是我的解决方案:
我找到了插件Jenkins Poll SCM,它在尝试构建之前轮询 SCM(仅在必要时)。
CloudBees Build Flow 插件的唯一问题是它不会等待以前的作业完成,因为我没有使用 build() 方法。为了克服这个问题,我创建了自己的 buildWithPolling() 方法,等待工作完成后再继续。我的方法唯一的缺点是它不等待下游作业完成(但我不知道它是否也适用于 build() 方法......)。这是我的方法的代码:
def buildWithPolling(project)
{
//Connection to the URL starting the polling, and starting the building if needed
def address = "http://localhost:8080/jenkins/job/" + project + "/poll"
println "Connexion à " + address + " pour scrutation du Git et build si besoin est."
def poll = new URL(address)
poll.openStream()
//Declaration of variables used to know if the build is still running, or if it is finished
boolean inProgress = true
def parser = new XmlParser()
def rootNode = null;
address = "http://localhost:8080/jenkins/job/" + project + "/lastBuild/api/xml?depth=1&tree=building&xpath=*/building"
while(inProgress) {
//A 5 seconds pause, because we don't need to overload the server
sleep(5000)
//Request sent to the server, to know if the job is finished.
def baos =new ByteArrayOutputStream()
baos << new URL(address).openStream()
rootNode = parser.parseText(new String(baos.toByteArray()))
inProgress = rootNode.text().toBoolean()
}
}
这可能不是最好的解决方案,但它对我有用!
不确定,如果您查看了作业设置中的配置。有一个地方可以强制重新结帐。我有 svn 链接,类似的事情将与 git
如果没有,您可以寻找添加手动命令,如下所示。检查您是否可以安排此顺序首先执行然后构建您的任务