James Wang
James Wang

Reputation: 144

How to trigger a individual job in jenkins with github repository

Our project is hosted on github and we've setup a Jenkins server, the question is we have lots of modules in the project and every module has it's own job, previously we were using perforce that it can update source code in specified modules thus only the jobs belong to those modules which have been modified will be triggered, but git will treat the whole project as a single repository and it won't tell us which modules have been modified therefore Jenkinks can't do the same thing.

I've investigated on git submodule and git subtree, seems all of them are a little complicated, is there a easier way to archive this?

Upvotes: 1

Views: 981

Answers (3)

MrMister
MrMister

Reputation: 2536

Nowadays you can make use of the regular Git plugin of Jenkins: you can set which directories it should watch and commence the execution of the job, and which to ignore. This works best if you have a build job for each project/module in the repository, and you want to invoke the build only when relevant directories have been changed (for example, the very directory of the module, and any commons/shared module directories).

To drive the point home, we don’t have build jobs for the shared module, but we do have, naturally, jobs for every module. So we set the plugin to watch only the module’s directory and the commons directory: this way the project will be rebuilt on every relevant commit to the directory, as well as commits to the commons directory.

Upvotes: 1

James Wang
James Wang

Reputation: 144

I have created a Jenkins Plugin to achieve this goal, it's here https://github.com/jameswangz/github-shared-repository.

Upvotes: 1

Dietrich Epp
Dietrich Epp

Reputation: 213248

Git will tell you this information with git log (see the --exit-code parameter, which is implied by --quiet). I don't know if the Jenkins Git plugin will will give you this kind of finesse, but you can do it with a simple shell script easily enough.

To check if the directory dir changed between revision A and B,

if git log --quiet A..B -- dir ; then
    # there are no changes in "dir" between rev A and B
else
    # there are changes
fi

Upvotes: 1

Related Questions