Skip to content

Instantly share code, notes, and snippets.

@lusoal
Created May 31, 2019 17:55
Show Gist options
  • Select an option

  • Save lusoal/413e6e037464b0d7c1c7e2245d2348cb to your computer and use it in GitHub Desktop.

Select an option

Save lusoal/413e6e037464b0d7c1c7e2245d2348cb to your computer and use it in GitHub Desktop.
Git SharedLib Jenkins
#!groovy
package libs.git;
def String cloneAndCheckout(String REPO, String REPO_NAME, String BRANCH){
script {
sh "git clone --depth 1 ${REPO} && cd ${REPO_NAME} && git checkout ${BRANCH}"
PWD = sh (
script: "cd ${REPO_NAME} && pwd",
returnStdout: true
).trim()
return PWD
}
}
def String getShortCommitHash(String REPO_PWD) {
script {
shortCommit = sh (
script: "cd ${REPO_PWD} && git log -n 1 --pretty=format:'%h'",
returnStdout: true
).trim()
return shortCommit
}
}
def void gitCloneBranchPR(gitCredentials, gitRepo, repoName) {
checkout([$class: 'GitSCM',
branches: [[name: '${sha1}']],
doGenerateSubmoduleConfigurations: false,
extensions: [],
gitTool: 'Default',
submoduleCfg: [],
userRemoteConfigs: [[refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pr/*', url: "${gitRepo}"]]])
}
return this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment