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 On Sun, 12 Jan 2025 at 10:14, Michael Nazzareno Trimarchi < [email protected]> wrote: > Hi James > > On Sun, Jan 12, 2025 at 10:47 AM James Nord <[email protected]> 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 > > > Regards > > > > /James > > On Saturday, 11 January 2025 at 14:52:31 UTC [email protected] > wrote: > >> > >> Hi Mark > >> > >> On Sat, Jan 11, 2025 at 3:16 PM Mark Waite <[email protected]> > wrote: > >> > > >> > > >> > > >> > On Saturday, January 11, 2025 at 4:22:58 AM UTC-7 Michael wrote: > >> > > >> > Hi all > >> > > >> > Is it possible to use git clone from sh context but then populate as I > >> > had clone using gitscm? > >> > > >> > > >> > 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. > >> > > >> > >> 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 [email protected]. > >> > 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 > >> [email protected] > >> __________________________________ > >> > >> Amarula Solutions BV > >> Joop Geesinkweg 125, 1114 AB, Amsterdam, NL > >> T. +31 (0)85 111 9172 > >> [email protected] > >> www.amarulasolutions.com > > > > -- > > 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 [email protected]. > > To view this discussion visit > https://groups.google.com/d/msgid/jenkinsci-dev/4fb0794a-e327-42f8-864f-886bf1ab3f97n%40googlegroups.com > . > > > > -- > Michael Nazzareno Trimarchi > Co-Founder & Chief Executive Officer > M. +39 347 913 2170 > [email protected] > __________________________________ > > Amarula Solutions BV > Joop Geesinkweg 125, 1114 AB, Amsterdam, NL > T. +31 (0)85 111 9172 > [email protected] > www.amarulasolutions.com > > -- > 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 [email protected]. > To view this discussion visit > https://groups.google.com/d/msgid/jenkinsci-dev/CAOf5uwnzjQgGtDfJTCrh0Y6BHYPJC2CskqhUCFOL0345UNYcjQ%40mail.gmail.com > . > -- 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 [email protected]. To view this discussion visit https://groups.google.com/d/msgid/jenkinsci-dev/CAPzq3pc_ks-G9256g397Xawx2Q5GNMWEDw%2BCSdkMiAR6kosbmQ%40mail.gmail.com.
