I need to use Active Choices Reactive Parameter in my jenkinsfile with below groovy script:
def gettags = ("git ls-remote -t -h https://USER:PASS@bitbucket.org/project_name.git").execute()
return gettags.text.readLines().collect {
it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}
How do I define this param in my jenkinsfile?
I have used below code :
properties([
parameters([
[$class: 'ChoiceParameter', choiceType: 'PT_SINGLE_SELECT',
description: 'Select code branch name',
name: 'code_release_branch',
script: [$class: 'GroovyScript',
fallbackScript: [classpath: [], sandbox: false,
script: 'return ["error"]'],
script: [classpath: [], sandbox: false,
script: '''def gettags=("git ls-remote -t -h ssh://git@abc.com/code/code.git").execute()return gettags.text.readLines().collect{it.split([1].replaceAll('refs/heads/','').replaceAll('refs/tags/','').replaceAll("\\^\\{\\}",'')}}''']]],
])
])
This gives "error" output in parameter
Please note that this groovy script is to get branch names from git dynamically
I have tried one more thing of putting this groovy script in Jenkins managed files and give the id as a parameter to script as below , but still same issue:
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select code branch name',
name: 'code_release_branch', script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: 'return ["ERROR"]'
],
script: [
classpath: [],
sandbox: false,
script: '6cd2a674-c02d-44b0-87cb-b32f1fcdc0c3'
]
]],
])
])