gitscm git data populate

89 views
Skip to first unread message

Michael Nazzareno Trimarchi

unread,
Jan 11, 2025, 6:22:58 AMJan 11
to jenkin...@googlegroups.com
Hi all

Is it possible to use git clone from sh context but then populate as I
had clone using gitscm?

Michael

Mark Waite

unread,
Jan 11, 2025, 9:16:34 AMJan 11
to Jenkins Developers
Not really.  Maybe you could approximate it by calling checkout scm with parameters that try to duplicate your git clone parameters and use the return value from checkout scm.

Mark Waite

Michael Nazzareno Trimarchi

unread,
Jan 11, 2025, 9:52:31 AMJan 11
to jenkin...@googlegroups.com
Hi Mark
Right now what I'm trying to do is something like this and change groovy library

- def git_opts = history ? '--filter=tree:0' : '--depth 1'
+ def depth = history ? 0 : 1
def updateRepository = {
- if (context.fileExists(directory)) {
- context.dir(directory) {
- context.sh """
- git remote remove origin
- git remote add origin ${url}
- git remote set-branches --add origin ${branch}
- git fetch origin ${branch} ${git_opts}
- git reset --hard FETCH_HEAD
- """
- }
- } else {
- context.sh "git clone ${git_opts} --branch ${branch}
${url} ${directory}"
- }
+ context.checkout(
+ changelog: true,
+ poll: false,
+ scm: [
+ $class: 'GitSCM',
+ branches: [[name: "*/${branch}"]],
+ extensions: [
+ [$class: 'cleanAfterCheckout',
deleteUntrackedNestedRepositories: true],
+ [$class: 'RelativeTargetDirectory',
relativeTargetDir: "${directory}"],
+ [$class: 'CloneOption', depth: "${depth}",
honorRefspec: true, noTags: false, \
+ reference: "${directory}", shallow:
depth > 0 ? true : false
+ ]
+ ],
+ userRemoteConfigs: [
+ [credentialsId: "${credentials}", url: "${url}"]
+ ]
+ ]
+ )
}


This is not exactly the same (by the way needs to be tested) but using
gitscm I have a lot more features. Would be nice to allow
gitscm to re-evaluate some already checkout or already .git on
filesystem to calculate the data. Looking at several plugins does not
sound very easy. The reason that I'm moving to using gitscm is to
integrate plugins like git-forensic etc. I have found gitSCM really
nice
but could be a bit limited if you are trying to have more git
flexibility. Like in this case I can not use --filter=tree:0'

Michael


> Mark Waite
>
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/jenkinsci-dev/ea47d6bd-097f-41b2-a223-ae42d1277853n%40googlegroups.com.



--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mic...@amarulasolutions.com
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
in...@amarulasolutions.com
www.amarulasolutions.com

James Nord

unread,
Jan 12, 2025, 4:46:55 AMJan 12
to Jenkins Developers
Take a little ok at the clone and checkout traits https://javadoc.jenkins.io/plugin/git/jenkins/plugins/git/traits/package-summary.html

It would appear that you should be able to do this with a new trait.

Regards

/James

Michael Nazzareno Trimarchi

unread,
Jan 12, 2025, 5:14:35 AMJan 12
to jenkin...@googlegroups.com
Hi James

On Sun, Jan 12, 2025 at 10:47 AM James Nord <james...@gmail.com> wrote:
>
> Take a little ok at the clone and checkout traits https://javadoc.jenkins.io/plugin/git/jenkins/plugins/git/traits/package-summary.html
>
> It would appear that you should be able to do this with a new trait.
>

I miss here a bit. It should be help to extend some clone or checkout
option? Like --filter=tree:0

Michael
> To view this discussion visit https://groups.google.com/d/msgid/jenkinsci-dev/4fb0794a-e327-42f8-864f-886bf1ab3f97n%40googlegroups.com.

James Nord

unread,
Jan 12, 2025, 10:29:38 AMJan 12
to jenkin...@googlegroups.com
I Michael,

if the reason you are needing to clone / checkout via sh is due to passing some flags like `  --filter=tree:0` then I thought you would be able to implement that by extending https://javadoc.jenkins.io/plugin/git/jenkins/plugins/git/traits/CloneOptionTrait.html and creating a special trait for it ( e.g. a TreeLessCloneTrait) and get Jenkins to do the checkout at least with the cli base git implementation and add ind some extra flags to the CLI arg..

However it appears I am mistaken and this would actually need new methods / support in `CloneOption` (and possible `FetchOption`) and the support to be in the git plugin and the git client plugin.

So let's flip this around, what functionality is missing that prevents you from cloning / fetching from Jenkins as opposed to from the cli via an sh step, is it just the treeless clone?

Regards

/James

Michael Nazzareno Trimarchi

unread,
Jan 12, 2025, 10:36:13 AMJan 12
to jenkin...@googlegroups.com
Hi James

On Sun, Jan 12, 2025 at 4:29 PM James Nord <james...@gmail.com> wrote:
>
> I Michael,
>
> if the reason you are needing to clone / checkout via sh is due to passing some flags like ` --filter=tree:0` then I thought you would be able to implement that by extending https://javadoc.jenkins.io/plugin/git/jenkins/plugins/git/traits/CloneOptionTrait.html and creating a special trait for it ( e.g. a TreeLessCloneTrait) and get Jenkins to do the checkout at least with the cli base git implementation and add ind some extra flags to the CLI arg..
>
> However it appears I am mistaken and this would actually need new methods / support in `CloneOption` (and possible `FetchOption`) and the support to be in the git plugin and the git client plugin.
>
> So let's flip this around, what functionality is missing that prevents you from cloning / fetching from Jenkins as opposed to from the cli via an sh step, is it just the treeless clone?
>

Not really, I'm thinking that in general it would be nice to be able
to create a gitscm object from an already checkout object from git
tool. Some examples come with kas that are used to checkout projects
using git tool (https://github.com/siemens/kas), but then if I have a
way to generate objects on top of checkout coming from a third party
tool would be nice. No TreeLessClone Traits can be added and so on

Michael
> To view this discussion visit https://groups.google.com/d/msgid/jenkinsci-dev/CAPzq3pc_ks-G9256g397Xawx2Q5GNMWEDw%2BCSdkMiAR6kosbmQ%40mail.gmail.com.

Michael Nazzareno Trimarchi

unread,
Dec 5, 2025, 2:29:08 AM (10 days ago) Dec 5
to jenkin...@googlegroups.com
Hi all

On Sun, Jan 12, 2025 at 4:35 PM Michael Nazzareno Trimarchi
<mic...@amarulasolutions.com> wrote:
>
> Hi James
>
> On Sun, Jan 12, 2025 at 4:29 PM James Nord <james...@gmail.com> wrote:
> >
> > I Michael,
> >
> > if the reason you are needing to clone / checkout via sh is due to passing some flags like ` --filter=tree:0` then I thought you would be able to implement that by extending https://javadoc.jenkins.io/plugin/git/jenkins/plugins/git/traits/CloneOptionTrait.html and creating a special trait for it ( e.g. a TreeLessCloneTrait) and get Jenkins to do the checkout at least with the cli base git implementation and add ind some extra flags to the CLI arg..
> >
> > However it appears I am mistaken and this would actually need new methods / support in `CloneOption` (and possible `FetchOption`) and the support to be in the git plugin and the git client plugin.
> >
> > So let's flip this around, what functionality is missing that prevents you from cloning / fetching from Jenkins as opposed to from the cli via an sh step, is it just the treeless clone?
> >
>
> Not really, I'm thinking that in general it would be nice to be able
> to create a gitscm object from an already checkout object from git
> tool. Some examples come with kas that are used to checkout projects
> using git tool (https://github.com/siemens/kas), but then if I have a
> way to generate objects on top of checkout coming from a third party
> tool would be nice. No TreeLessClone Traits can be added and so on
>

Moving most of the implementation using gitscm to collect data object
but I found a new restriction:

18:40:53 Warning: A secret was passed to "checkout" using Groovy
String interpolation, which is insecure. 18:40:53 Affected argument(s)
used the following variable(s): [GERRIT_RESTAPI_USER] 18:40:53 See
https://jenkins.io/redirect/groovy-string-interpolation for details.
18:40:53 The recommended git tool is: NONE 18:40:54 No credentials
specified 18:40:54 Warning: JENKINS-30600: special launcher

Now, my checkout are not using credentials passed using the
credentialsid in gitscm but using ssh-agent, the reason is that
I need more then one credentials when I need to deal with a project
that can potentially download other git projects in order
to build an entire OS. I think that here the commands are not
executed inside the container but outside and the ssh agent is running
inside it. Is this correct?

Is it really needed to check out things outside the docker container
with gitscm? Can I just run the gitscm command inside the docker
launcher instance?

Michael

Michael Nazzareno Trimarchi

unread,
Dec 6, 2025, 3:21:37 AM (9 days ago) Dec 6
to jenkin...@googlegroups.com
Hi all

https://github.com/amarula/git-collect-plugin/tree/main

I think that now, it is better to collect offline commits and use the plugin on
my shared library.

Michael

On Fri, Dec 5, 2025 at 8:28 AM Michael Nazzareno Trimarchi
Reply all
Reply to author
Forward
0 new messages