子引发詹金斯构建怎么走吗 - how to get submodules to trigger a Jenkins build

- 此内容更新于:2016-02-03
主题:

我有子模块,并不是一个独立的应用程序。它需要主应用程序工作。我想创建一个CI构建提交时被推到它与主项目代码触发一个构建。在詹金斯我该怎么做?我需要做什么:一个承诺一个触发一个构建。构建克隆主要项目代码,把最新最新提交的代码(不提交,主要项目知道)。我怎么使用詹金斯和GIT吗?请注意我有多个项目的子。子模块触发一个构建,把最新的变化以及最新的主要代码和从其他子拉更新。

原文:

I have a submodule A that is not a standalone application. It requires the main application for it to work. I would like to create a CI build for A so that whenever a commit is pushed to A it triggers a build with the main project code.

How do I do that in Jenkins?

What I need to do:

  • A commit to A triggers a build.
  • The build clones the Main project code and pulls the latest code for A at the latest commit for A (not the commit that the Main Project knows about).

How would I do that using Jenkins and GIT?

Note I have multiple submodules for the project. Submodule A triggers a build that pulls the latest changes from A and also the latest of main code and pulls updates from the other submodules.

解决方案:
这可以通过两个步骤:使一个构建触发詹金斯的工作你想建立的url。这样做是在“触发构建远程”选项卡。url形式:。设置一个gitpost-receive钩在子模块调用上面的url。这样做的一个简单方法是使用curl:。一个推动子模块将触发的主要项目詹金斯的工作通过调用的url。配置詹金斯工作之前更新它的代码构建或任何其他你需要的细节。这个答案提供了很多细节如何设置git钩。
原文:

This can be done in two steps:

  1. Enable a build trigger url on the Jenkins job you want to build. This is done under "Trigger builds remotely" tab. The url will be in the form: JENKINS_URL/job/MY_JOB_NAME/build?token=TOKEN_NAME.

  2. Setup a git post-receive hook in submodule A that calls the above url. An easy way to do so is simply to use curl: curl JENKINS_URL/job/MY_JOB_NAME/build?token=TOKEN_NAME.

A push to submodule A will then trigger the main project Jenkins's job by calling the url. Configure the Jenkins job to update its code before build or any other specifics you need.

This answer provides a lot of details on how to setup the git hook.