Guest User

Untitled

a guest
Dec 12th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. proc1 = ['/bin/bash', '-c', "/usr/bin/git ls-remote -h ssh://user@server.com/path/to/repo.git"].execute()
  2. proc2 = ['/bin/bash', '-c', "awk '{print $2}'"].execute()
  3. proc3 = ['/bin/bash', '-c', "sed s%^refs/heads%origin%"].execute()
  4.  
  5. all = proc1 | proc2 | proc3
  6. String result = all.text
  7.  
  8. String filename = "/tmp/branches.txt"
  9. boolean success = new File(filename).write(result)
  10.  
  11. def multiline = "cat /tmp/branches.txt".execute().text
  12. def list = multiline.readLines()
  13.  
  14. git ls-remote git@github.com:my/repo.git |grep refs/heads/* >tmp.txt
  15. sed -e 's/.*refs/heads///' tmp.txt > tmp2.txt
  16. tr 'n' ',' < tmp2.txt > tmp3.txt
  17. sed '1ibranches=' tmp3.txt > tmp4.txt
  18. tr -d 'n' < tmp4.txt > branches.txt
  19.  
  20. <?php
  21. chdir('/path/to/repo');
  22. exec('git branch -r', $output);
  23. print('branches='.str_replace(' origin/','',implode(',', $output)));
  24. ?>
  25.  
  26. <?php
  27. exec('git ls-remote -h http://user:pass@repo.git', $output);
  28. print('branches='.preg_replace('/[a-z0-9]*trefs/heads//','',implode(',', $output)));
  29. ?>
  30.  
  31. #!/usr/bin/groovy
  32.  
  33. def gitURL = "git repo url"
  34. def command = "git ls-remote --heads --tags ${gitURL}"
  35.  
  36. def proc = command.execute()
  37. proc.waitFor()
  38.  
  39. if ( proc.exitValue() != 0 ) {
  40. println "Error, ${proc.err.text}"
  41. System.exit(-1)
  42. }
  43.  
  44. def text = proc.in.text
  45. # put your version string match
  46. def match = /<REGEX>/
  47. def tags = []
  48.  
  49. text.eachMatch(match) { tags.push(it[1]) }
  50. tags.unique()
  51. tags.sort( { a, b ->
  52. def a1 = a.tokenize('._-')
  53. def b1 = b.tokenize('._-')
  54. try {
  55. for (i in 1..<[a1.size(), b1.size()].min()) {
  56. if (a1[i].toInteger() != b1[i].toInteger()) return a1[i].toInteger() <=> b1[i].toInteger()
  57. }
  58. return 1
  59. } catch (e) {
  60. return -1;
  61. }
  62. } )
  63. tags.reverse()
  64.  
  65. import jenkins.model.Jenkins
  66.  
  67. def envVars = Jenkins.instance.getNodeProperties()[0].getEnvVars()
  68. def GIT_PROJECT_PATH = envVars.get('GIT_PROJECT_PATH')
  69. def gettags = "git ls-remote -t --heads origin".execute(null, new File(GIT_PROJECT_PATH))
  70.  
  71. return gettags.text.readLines()
  72. .collect { it.split()[1].replaceAll('\^\{\}', '').replaceAll('refs/\w+/', '') }
  73. .unique()
  74.  
  75. proc1 = ['/bin/bash', '-c',
  76. "/usr/bin/git ls-remote --heads ssh://repo_url.git"].execute()
  77. proc2 = ['/bin/bash', '-c',
  78. "/usr/bin/awk ' { gsub(/refs\/heads\//, ""); print $2 }' "].execute()
  79. all = proc1 | proc2
  80.  
  81. choices = all.text
  82. return choices.split().toList();
Add Comment
Please, Sign In to add comment