scm.gitTool in Jenkinsfile

178 views
Skip to first unread message

Nigel Magnay

unread,
Jul 27, 2016, 3:57:14 PM7/27/16
to jenkins...@googlegroups.com
In a bitbucket-sourced multibranch repository, I need to ensure the git checkout doesn't occur with /usr/bin/git, but with a tool that stands a chance of executing on Windows.

I had rather hoped it would simply be the case of doing

scm.gitTool = 'win git';

before my
checkout scm

But it still seems to insist on using the wrong binary (even though there appears to be a setter, as I had to approve it in the script console).

What have I missed?



Mark Waite

unread,
Jul 27, 2016, 4:53:58 PM7/27/16
to jenkins...@googlegroups.com
Have you tried configuring your git executable to be "git" rather than "/usr/bin/git"?  That's what I've used in multi-platform environments and it has worked well for me.

Mark Waite

--
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/CAPYP83SpLOHmoJBupi6Q0QV6TDjKOf9EYtbXrtj3NZ0L9f1PTg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Nigel Magnay

unread,
Jul 27, 2016, 4:56:53 PM7/27/16
to jenkins...@googlegroups.com
No, as it's not on the path so would not be found.

Oddly, if I do
scm.gitTool = 'win git'
echo scm.gitTool

it responds with 'null' - so something is odd in the field setter :-/


nicolas de loof

unread,
Jul 28, 2016, 12:16:44 AM7/28/16
to jenkins...@googlegroups.com

Any reason you don't set git in default path ? Would be so simpler ;)

Nigel Magnay

unread,
Jul 28, 2016, 2:48:14 AM7/28/16
to jenkins...@googlegroups.com
The host it builds on is not under my control.

Is manipulating fields in scm not supposed to work?

Mark Waite

unread,
Jul 28, 2016, 7:13:03 AM7/28/16
to jenkins...@googlegroups.com
I wonder if the sematnics of scm.gitTool are closer to the GitTool object semantics inside the git plugin.  GitTool inside the git plugin allows job owner to choose which git implementation will be used.  It doesn't allow the job owner to specify the destination of the git executable.

You might try defining a new git implementation in the "Global Tool Configuration" under the "Git installations" section.  You can set the git location from that spot in the configuration and give that new git installation a distinct name ("win-git").  Then assign "win-git" git scm.gitTool and see if that has the desired affect.

Mark Waite

Nigel Magnay

unread,
Jul 28, 2016, 8:51:55 AM7/28/16
to jenkins...@googlegroups.com
Aha - I have found it.

BTW - I was already expecting it to be the tool name itself in the manner you're describing (sorry if I wasn't clear about that).

If I do the following:

echo scm.gitTool;
scm.gitTool = 'win-git';
echo scm.gitTool;


​The 1st run through I get 

Scripts not permitted to use field hudson.plugins.git.GitSCM gitTool

After approving the access, it I get "null" printed out twice.

However, if you do 

def myScm = scm;
echo myScm.gitTool;
myScm.gitTool = 'win-git';
echo myScm.gitTool;

​It operates as expected! Hurrah!

Clearly scm is actually a function that returns a 'new' SCM object matching the correct criteria and I've just been caught out by the semantics.​


Reply all
Reply to author
Forward
0 new messages