Cannot set Git executable using Job DSL

84 views
Skip to first unread message

shaneoh1980 McP

unread,
Jan 5, 2017, 11:16:52 AM1/5/17
to Jenkins Users
I'm converting all of our Jenkins jobs to DSL scripts and I've come accross one where we use a Git executable other than the "default" one. 

I've spent two days trying to get this to work and no matter what I do it just won't work. I need this in the config.xml which gets generated for the job ("Ubuntu Git" is the name of one of our Git installations which is configured as a tool for the Jenkins server):

<gitTool>Ubuntu Git</gitTool>

But no matter what I do I always end up with:

<gitTool>default</gitTool>

It doesn't seem to be supported by the DSL so I have been using the configure block. I've tried hundreds of ways but the way I most expected to work is below. Note that I am new to using the configure block. This is starting to drive me spare - does anyone know what is wrong in this configure block that I have? Or, am I somehow missing that this is actually natively supported by the job dsl?


job('job') {
  scm
{
    git
{
      remote
{
        url
('https://github.com/mygithub/project.git')
        credentials
('25dwere85ds-dgh6-5874-6954-e226asdasd07e7')
        branches
('*/my_branch')
       configure { project ->
         project
<< 'hudson.plugins.git.GitSCM' {
           paramDefs
<< 'gitTool' {
             
string('Ubuntu Git')
               
}
           
}
         
}
     
}
   
}
}


I would appreciate any advice.

Indra Gunawan (ingunawa)

unread,
Jan 5, 2017, 3:04:13 PM1/5/17
to jenkins...@googlegroups.com

You need to configure in “job” block not “git” block like :

 

job(‘job’) {

  scm {

    git {

     …

    } //git

  } //scm

 

  configure { project ->

                project / scm(class: ‘hudson.plugins.git.GitSCM’) {

                                gitTool ‘Ubuntu Git’

                } //project

} //configure

} //job

--
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/d16271ae-207d-41a5-b926-2071a8ab9055%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

shaneoh1980 McP

unread,
Jan 6, 2017, 2:44:12 AM1/6/17
to Jenkins Users, ingu...@cisco.com
Thanks - but that generates a separate block of XML, with what I want, but it doesn't apply it to the git scm and therefore has no effect on the job.  In other words, inside the XML for git, I still see:

<gitTool>Default</gitTool>


But then outside that, in a separate block, I see:

    <scm(class: ‘hudson.plugins.git.GitSCM’)>
       
<gitTool>Ubuntu Git</gitTool>
   
</scm(class: ‘hudson.plugins.git.GitSCM’)>
</project>

shaneoh1980 McP

unread,
Jan 6, 2017, 5:35:32 AM1/6/17
to Jenkins Users, ingu...@cisco.com
I should add that if I create a job using this as a seed job, the default option is still selected.

Indra Gunawan (ingunawa)

unread,
Jan 6, 2017, 1:02:59 PM1/6/17
to shaneoh1980 McP, Jenkins Users

This one works correctly (put configure block inside git block).

 

    scm {

        git {

            remote {

                ..

            }

             configure { node ->

                                node / gitTool << 'Ubuntu Git'

             }

         }

   …

shaneoh1980 McP

unread,
Jan 16, 2017, 10:34:55 AM1/16/17
to Jenkins Users, shane.do...@gmail.com, ingu...@cisco.com
Thank you! That worked. Thanks a lot for your help.
Reply all
Reply to author
Forward
0 new messages