Created
September 7, 2022 20:16
-
-
Save medguywalker/e2beac3b352b0cd939f7c7b4c95a7b08 to your computer and use it in GitHub Desktop.
git clone scripted pipeline
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
| // Disclaimer: this is provided “as is” without warranty of any kind, either expressed or implied and such is to be used at your own risk. | |
| // Dependencies | |
| // ---------------------- | |
| // Setting up Github credential with Jenkins's Credential Manager ( https://www.youtube.com/watch?v=HSA_mZoADSw&t=40s ) | |
| // Jenkins Plugin to Clean Workspace ( https://plugins.jenkins.io/ws-cleanup/ ) | |
| // Large File Storage ( https://git-lfs.github.com/ ) | |
| // Variables | |
| // ---------------------- | |
| github_source = {name_of_branch_or_tag} | |
| github_org = {name_of_github_organization_or_user} | |
| github_repo = {name_of_github_repository} | |
| credentials_id = {github_login_saved_to_jenkins_credentials_manager} | |
| jenkins_node = {name_of_the_jenkins_node_being_used} | |
| // Function(s) | |
| // ---------------------- | |
| def handleCheckout = { | |
| def regGithubSource = ~/^v[\d|.]+/ | |
| is_tag = regGithubSource.matcher(github_source).matches() | |
| if (is_tag == true) { | |
| gitref = 'refs/tags/' | |
| } else { | |
| gitref = 'refs/heads/' | |
| } | |
| checkout([ | |
| $class: 'GitSCM', | |
| branches: [[name: gitref + github_source]], | |
| doGenerateSubmoduleConfigurations: false, | |
| extensions: [ | |
| [ | |
| $class: 'CloneOption', | |
| noTags: false, | |
| shallow: false, | |
| depth: 0, | |
| reference: '' | |
| ], | |
| [ | |
| $class: 'SubmoduleOption', | |
| depth: 1, | |
| disableSubmodules: false, | |
| parentCredentials: true, | |
| recursiveSubmodules: true, | |
| reference: '', | |
| shallow: true, | |
| trackingSubmodules: false | |
| ], | |
| [$class: 'GitLFSPull'] | |
| ], | |
| submoduleCfg: [], | |
| userRemoteConfigs: [[ credentialsId: credentials_id, url: 'https://github.com/' + github_org + '/' + github_repo + '.git']] | |
| ]); | |
| } | |
| // Pipeline | |
| // ---------------------- | |
| node (jenkins_node) { | |
| stage('Git Clone Scripted Pipeline') { | |
| handleCheckout() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment