Advertisement
METAJIJI

git obtain rev list

Jun 23rd, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 0.86 KB | None | 0 0
  1. def get_git_branches(url, secretfileId) {
  2.     def isport = url.split(':'); def port = ''
  3.     if (isport.size() >= 3) {
  4.         port = '-p ' + isport[2].split('/')[0]
  5.     }
  6.     def revisions_list = []; def branches = []
  7.     withCredentials([[$class: 'FileBinding', credentialsId: secretfileId, variable: 'GITLAB_SSH_KEY']]) {
  8.         revisions_list = sh(returnStdout: true, script: "GIT_SSH_COMMAND='ssh $port -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i $GITLAB_SSH_KEY' git ls-remote -t -h $url").split('\r?\n')
  9.     }
  10.     for (def revision in revisions_list) {
  11.         def branch = revision.split('\t')[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll(/[\^].*/, '')
  12.         branches.add(branch)
  13.     }
  14.     return branches.unique()
  15. }
  16.  
  17. ....
  18.  
  19. def configs_branches = get_git_branches(configs_repo_url, gitlab_secretfileId)
  20. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement