Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins triggers with git sparse checkout

I have a big git repository and I created multiple jobs for it in Jenkins.
I used git sparse checkout feature to sync each time only the necessary part of it.
Also I hoped that the SCM polling function would trigger only when the changes happen on the related part of the code. In fact it is triggering all the jobs whatever the commit is on.

My Question : How can I ensure a job is triggered only when its related files are changed ?
Also, would a switch from "Jenkins polling GIT" to "trigger from Gitlab" allow solve this ?

like image 750
Gurvan Avatar asked Jul 05 '16 11:07

Gurvan


People also ask

How does git sparse checkout work?

"Sparse checkout" allows populating the working directory sparsely. It uses the skip-worktree bit (see git-update-index[1]) to tell Git whether a file in the working directory is worth looking at. If the skip-worktree bit is set, and the file is not present in the working tree, then its absence is ignored.

How do I enable sparse checkout?

To get started with the sparse-checkout feature, you can run git sparse-checkout init --cone to restrict the working directory to only the files at root (and in the . git directory). For more complicated scenarios, the architecture team created a boostrap.sh script at the root of the repository.

How does Jenkins pull from git?

The key to Jenkins Git integration is the Git plug-in. One can easily install the Jenkins Git plug-in through the Jenkins administrative console, and once properly configured, it gives all Jenkins build jobs the option to pull content from a Git-compatible source code repository.


1 Answers

There is an option under the Additional Behaviours dropdown list of the Jenkins Git Plugin called Polling ignores commit in certain paths. There you can specify included and excluded paths to control the behavior of SCM polling.

From the Plugin's documentation:

Each inclusion uses regular expression pattern matching, and must be separated by a new line.
An empty list implies that everything is included.

    myapp/src/main/web/.*\.html
    myapp/src/main/web/.*\.jpeg
    myapp/src/main/web/.*\.gif

The example above illustrates that a build will only occur, if html/jpeg/gif files have been committed to the SCM.
Exclusions take precedence over inclusions, if there is an overlap between included and excluded regions.
like image 109
Martin Avatar answered Oct 07 '22 18:10

Martin