Git Plugin: merge before build not working?

1,632 views
Skip to first unread message

Martin d'Anjou

unread,
Apr 6, 2016, 9:13:37 PM4/6/16
to Jenkins Users
I'm trying to get the Git Plugin to merge a branch to master before build, in a Pipeline DSL script, but it's not convincingly working yet. After the checkout step has run, a quick "git log --graph" command does not reveal a merge. The Pipeline DSL code I have is:

node {
    checkout
([
        $class
: 'GitSCM',
        branches
: [[name: 'refs/heads/master']],
        userRemoteConfigs
: [[
            name
: 'origin',
            refspec
: 'pull-requests/1/from',
            url
: path
       
]],
        extensions
:
       
[[
            $class
: 'PreBuildMerge',
            options
: [
                fastForwardMode
: 'NO_FF',
                mergeRemote
: 'origin',
                mergeStrategy
: 'MergeCommand.Strategy',
                mergeTarget
: 'master'
           
]
       
]]
   
])
    sh
'git log -n 10 --graph --pretty=oneline --abbrev-commit --all --decorate=full'
}

And the resulting log:

 
[Pipeline] checkout
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 
> git config remote.origin.url /tmp/jenkins/upstream-repo # timeout=10
Fetching upstream changes from /tmp/jenkins/upstream-repo
 
> git --version # timeout=10
 
> git -c core.askpass=true fetch --tags --progress /tmp/jenkins/upstream-repo pull-requests/1/from
 
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 
> git rev-parse refs/remotes/origin/refs/heads/master^{commit} # timeout=10
Merging Revision 19e39345b1b178e3ebc4c5b3af277cbd64c37f9f (refs/remotes/origin/master) to origin/master, UserMergeOptions{mergeRemote='origin', mergeTarget='master', mergeStrategy='MergeCommand.Strategy', fastForwardMode='--no-ff'}
 
> git rev-parse origin/master^{commit} # timeout=10
 
> git config core.sparsecheckout # timeout=10
 
> git checkout -f origin/master
 
> git merge --no-ff 19e39345b1b178e3ebc4c5b3af277cbd64c37f9f # timeout=10
 
> git rev-parse HEAD^{commit} # timeout=10
Seen branch in repository origin/HEAD
Seen branch in repository origin/master
Seen branch in repository origin/pull-requests/1/from
Seen 3 remote branches
Checking out Revision 19e39345b1b178e3ebc4c5b3af277cbd64c37f9f (origin/master, origin/master)
 
> git config core.sparsecheckout # timeout=10
 
> git checkout -f 19e39345b1b178e3ebc4c5b3af277cbd64c37f9f
 
> git rev-list 19e39345b1b178e3ebc4c5b3af277cbd64c37f9f # timeout=10
 
> git rev-list 19e39345b1b178e3ebc4c5b3af277cbd64c37f9f # timeout=10
[Pipeline] sh
[workspace] Running shell script
+ git log -n 10 --graph --pretty=oneline --abbrev-commit --all --decorate=full
* 3644c2e (refs/remotes/origin/pull-requests/1/from, refs/remotes/origin/HEAD, refs/heads/pull-requests/1/from) Add file
* 19e3934 (HEAD, refs/remotes/origin/master, refs/heads/master) init

It should end with the git log showing a merge (3 commits), but it only shows two commits. Full code and log as github gists.

Anyone tried this yet? Any ideas?

Thanks,
Martin

David Karlsen

unread,
Apr 22, 2016, 8:32:49 AM4/22/16
to Jenkins Users
Anyone got this to work? I'm running this in context of the multibranch pipeline plugin - so I'd like to get whatever branch is triggered to merge into an integration-branch before building, then pushing back to the integration branch if the build succeeds. 

Björn Pedersen

unread,
Apr 22, 2016, 9:39:19 AM4/22/16
to Jenkins Users
Hi,

for me it wis working fine, although the setup is slightly different:

1) I have the full refspec specified: refs/...:refs/...
2) Additionally I use the gerrit trigger checkout strategy to really build a specific change.

    checkout(changelog: false, poll: false,
        scm: [$class: 'GitSCM',
            branches: [[name: "$GERRIT_BRANCH"]],
            doGenerateSubmoduleConfigurations: false, submoduleCfg: [],
            userRemoteConfigs: [[refspec: GERRIT_REFSPEC+':'+GERRIT_REFSPEC, url: '....']],
            extensions:[[$class:'hudson.plugins.git.extensions.impl.BuildChooserSetting',
                buildChooser:[$class:"com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerBuildChooser"] ],

               [
            $class: 'PreBuildMerge',
            options: [
                fastForwardMode: 'NO_FF',
                mergeRemote: 'origin',
                mergeStrategy: 'MergeCommand.Strategy',
                mergeTarget: 'master'
            ]
        ] ]
        ])


$GERRIT_BRANCH is normal master, GERRIT_REFSPEC points at a specific change, like your pull request refspecs.
Reply all
Reply to author
Forward
0 new messages