Skip to content

Instantly share code, notes, and snippets.

@martinda
Created April 6, 2016 23:40
Show Gist options
  • Save martinda/b2ece95c2c71ddb4d4a762f0a02561b3 to your computer and use it in GitHub Desktop.
Save martinda/b2ece95c2c71ddb4d4a762f0a02561b3 to your computer and use it in GitHub Desktop.
Jenkins Pipeline DSL code to demonstrate git merge before build
// Jenkins Pipeline DSL to demonstrate git merge before build
node {
String path = '/tmp/jenkins/upstream-repo'
sh "rm -rf ${path}"
ws(path) {
sh 'git --version'
sh 'git init'
sh 'touch README.md; git add README.md; git commit -m "init"'
sh 'git checkout -b pull-requests/1/from'
sh 'touch file.txt; git add file.txt; git commit -m "Add file"'
}
// sh "git clone ${path} ."
sh 'pwd; tree; ls;'
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'
]
],
[
$class: 'LocalBranch',
localBranch: 'master'
]]
])
sh 'git log -n 10 --graph --pretty=oneline --abbrev-commit --all --decorate=full'
}
Copy link

ghost commented Apr 27, 2018

could please help me out, git-merge-after-build.dsl help me

@gandadil
Copy link

I need to merge develop to master branch and I am using this approach. Do I need to push to git or this is done automatically at the end of my pipeline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment