Created
May 31, 2019 17:55
-
-
Save lusoal/413e6e037464b0d7c1c7e2245d2348cb to your computer and use it in GitHub Desktop.
Git SharedLib Jenkins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!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