-
Bug
-
Resolution: Not A Defect
-
Blocker
-
None
At the first stage of a pipeline groovy code, is not possible to execute a git command in order to list, for example, the branches from a repository without @NonCPS or out of sandbox, for example when you're using a SCM code.
Example:
String getBrancesList(String projectSSH) { def command = "git ls-remote -h ${projectSSH}" def proc = command.execute() proc.waitFor() if ( proc.exitValue() != 0 ) { println "Error, ${proc.err.text}" return 1; } def branches = proc.in.text.readLines().collect { it.replaceAll(/[a-z0-9]*\trefs\/heads\//, '') } int index = branches.indexOf("master"); branches.removeAt(index); branches.add(0, "master"); return branches.join("\n") } /////////////////////////////////////////////////////////////// node('my_node') { stage('job property') { def branchesList = getBrancesList("my@repo.git") properties( [ parameters( choice( choices: branchesList, description: 'Select the branch.', name: 'repository_branch' ) ) ] } } }
Using @NonCPS pasting the pipeline code in the job configuration works but it doesn't matter if you trying retrieving via SCM.
- is blocked by
-
JENKINS-26481 Mishandling of binary methods accepting Closure
- Resolved