GIT sparse checkout and triggering a build

171 views
Skip to first unread message

David Balazic

unread,
Oct 26, 2023, 5:45:52 PM10/26/23
to jenkins...@googlegroups.com
Hi!

I have two questions.

As our git repo content was split into two projects (the files stayed the same, we just build the two in two separate Jenkins jobs), the situation is like this:

The git root contains folders related to one project, for example foo1, foo2 and foo3 and folders related to other project (bar1, bar2) and some "unused" folders (baz1 and baz2).

How to set up a Jenkins job to:
- checkout only the folders foo1, foo2 and foo3 ?
- trigger a build only if those 3 folders are changed (and not if something inside bar2/ is changed) ?


For the first question I tried "Sparse Checkout paths" under "Additional Behaviours".
I entered as several Path entries: foo1, foo2 and foo3

It seems to work, but some other folders (like baz2) appear in the checkout (in the job workspace).

If I do this with command line git:
git clone --no-checkout --single-branch --branch main "https://gitserver/projects"
git sparse-checkout init --cone
git checkout
git sparse-checkout set foo1 foo2 foo3
cat .git/info/sparse-checkout
--> prints:
/*
!/*/
/AM/
/foo3/
/foo2/
/foo3/

And only those 3 folder are present in the worktree.

In the Jenkins job workspace the command "cat .git/info/sparse-checkout" prints:
foo1
foo2
foo3


I tried to change the job configuration (I actually created a new job) to use a slash prefix for the Path values: /foo1 /foo2 /foo3

Not the checkout has only the desired folders and cat .git/info/sparse-checkout prints:
/foo1
/foo2
/foo3

So, the slash is mandatory? The web GUI help does not mention it, neither does the web page https://plugins.jenkins.io/git/


Now the second issue: triggering the build

Even after the above, if there is a change in one of the other folders (for example bar1), the build is triggered.
Is this by design?

I now tried the " Polling ignores commits in certain paths" option (listed /foo1 /foo2 and /foo3*) and it seems that it does the job.

Any comments?
Can this be done differently?


* it is a bit inconsistent that here the paths are written all into one multiline text box, while for sparse checkout a new single line input element must be added for each path element

Lep pozdrav,
David Balažic

The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Any opinions expressed are mine and do not necessarily represent the opinions of the Company. Emails are susceptible to interference. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is strictly prohibited and may be unlawful. If you have received this message in error, do not open any attachments but please notify the Endava Service Desk on (+44 (0)870 423 0187), and delete this message from your system. The sender accepts no responsibility for information, errors or omissions in this email, or for its use or misuse, or for any act committed or omitted in connection with this communication. If in doubt, please verify the authenticity of the contents with the sender. Please rely on your own virus checkers as no responsibility is taken by the sender for any damage rising out of any bug or virus infection.

Endava plc is a company registered in England under company number 5722669 whose registered office is at 125 Old Broad Street, London, EC2N 1AR, United Kingdom. Endava plc is the Endava group holding company and does not provide any services to clients. Each of Endava plc and its subsidiaries is a separate legal entity and has no liability for another such entity's acts or omissions.

David Balazic

unread,
Nov 13, 2023, 9:08:30 AM11/13/23
to jenkins...@googlegroups.com
Hi!

After some more testing, I figured out the triggering part.

In the " Polling ignores commits in certain paths" option under " Included Regions" I added
^foo1/
^foo2/.*
^foo3/.*

Apparently the regex is matched against file paths that have the form:

foo1/folder1/folder2/file.ext
(no leading slash, unlike the sparse chekout paths)


A clearer documentation would be nice.

Regards,
David Balažic

(sorry fort he long email footer inserted by my organization)

-----Original Message-----
From: 'David Balazic' via Jenkins Users <jenkins...@googlegroups.com>
Sent: Thursday, 26 October 2023 22:33
To: jenkins...@googlegroups.com
Subject: GIT sparse checkout and triggering a build

CAUTION - EXTERNAL EMAIL
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/E7E8CAAA-0FC4-4E44-B33E-86E4DD77F3FF%40endava.com.

David Balazic

unread,
Nov 13, 2023, 9:17:19 AM11/13/23
to jenkins...@googlegroups.com
A small typo: the actual lines under "Included Regions" were:


^foo1/.*
^foo2/.*
^foo3/.*

Sorry,
David Balažic
Reply all
Reply to author
Forward
0 new messages