Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc1 = ['/bin/bash', '-c', "/usr/bin/git ls-remote -h ssh://user@server.com/path/to/repo.git"].execute()
- proc2 = ['/bin/bash', '-c', "awk '{print $2}'"].execute()
- proc3 = ['/bin/bash', '-c', "sed s%^refs/heads%origin%"].execute()
- all = proc1 | proc2 | proc3
- String result = all.text
- String filename = "/tmp/branches.txt"
- boolean success = new File(filename).write(result)
- def multiline = "cat /tmp/branches.txt".execute().text
- def list = multiline.readLines()
- git ls-remote git@github.com:my/repo.git |grep refs/heads/* >tmp.txt
- sed -e 's/.*refs/heads///' tmp.txt > tmp2.txt
- tr 'n' ',' < tmp2.txt > tmp3.txt
- sed '1ibranches=' tmp3.txt > tmp4.txt
- tr -d 'n' < tmp4.txt > branches.txt
- <?php
- chdir('/path/to/repo');
- exec('git branch -r', $output);
- print('branches='.str_replace(' origin/','',implode(',', $output)));
- ?>
- <?php
- exec('git ls-remote -h http://user:pass@repo.git', $output);
- print('branches='.preg_replace('/[a-z0-9]*trefs/heads//','',implode(',', $output)));
- ?>
- #!/usr/bin/groovy
- def gitURL = "git repo url"
- def command = "git ls-remote --heads --tags ${gitURL}"
- def proc = command.execute()
- proc.waitFor()
- if ( proc.exitValue() != 0 ) {
- println "Error, ${proc.err.text}"
- System.exit(-1)
- }
- def text = proc.in.text
- # put your version string match
- def match = /<REGEX>/
- def tags = []
- text.eachMatch(match) { tags.push(it[1]) }
- tags.unique()
- tags.sort( { a, b ->
- def a1 = a.tokenize('._-')
- def b1 = b.tokenize('._-')
- try {
- for (i in 1..<[a1.size(), b1.size()].min()) {
- if (a1[i].toInteger() != b1[i].toInteger()) return a1[i].toInteger() <=> b1[i].toInteger()
- }
- return 1
- } catch (e) {
- return -1;
- }
- } )
- tags.reverse()
- import jenkins.model.Jenkins
- def envVars = Jenkins.instance.getNodeProperties()[0].getEnvVars()
- def GIT_PROJECT_PATH = envVars.get('GIT_PROJECT_PATH')
- def gettags = "git ls-remote -t --heads origin".execute(null, new File(GIT_PROJECT_PATH))
- return gettags.text.readLines()
- .collect { it.split()[1].replaceAll('\^\{\}', '').replaceAll('refs/\w+/', '') }
- .unique()
- proc1 = ['/bin/bash', '-c',
- "/usr/bin/git ls-remote --heads ssh://repo_url.git"].execute()
- proc2 = ['/bin/bash', '-c',
- "/usr/bin/awk ' { gsub(/refs\/heads\//, ""); print $2 }' "].execute()
- all = proc1 | proc2
- choices = all.text
- return choices.split().toList();
Add Comment
Please, Sign In to add comment