Jenkinsfile活动选择参数插件(动态git分支名称)
我需要在Jenkins文件中使用Active Choices被动参数,并使用以下groovy脚本:Jenkinsfile活动选择参数插件(动态git分支名称),jenkins,groovy,parameters,jenkins-pipeline,jenkins-groovy,Jenkins,Groovy,Parameters,Jenkins Pipeline,Jenkins Groovy,我需要在Jenkins文件中使用Active Choices被动参数,并使用以下groovy脚本: 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('re
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("\\^\\{\\}", '')
}
如何在Jenkins文件中定义此参数
我使用了以下代码:
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("\\^\\{\\}",'')}}''']]],
])
])
这将在参数中给出“错误”输出
请注意,这个groovy脚本是从git动态获取分支名称的
我还尝试了一件事,将此groovy脚本放入Jenkins托管文件中,并将id作为脚本的参数,如下所示,但仍然存在相同的问题:
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'
]
]],
])
])
为什么不使用?@Joao。但使用此选项,分支名称只有在触发作业后才可用。我希望用户选择分支名称,然后运行jobNope。只需添加git repo,然后分支名称将在开始构建之前可用。我尝试了,但没有成功
properties([parameters([gitParameter(分支:“”,分支过滤器:'origin/(*)),defaultValue:'master',description:'',name:'BRANCH',quickFilterEnabled:false,selectedValue:'NONE',sortMode:'NONE',tagFilter:'*',type:'PT_BRANCH')]])节点{git branch:“${params.branch}”,url:'https://github.com/jenkinsci/git-parameter-plugin.git“}
是否有任何东西反对只使用输入步骤(除了您的要求“我需要使用活动参数”)?为什么不使用?@Joao。但是使用此选项,分支名称只有在触发作业后才可用。我希望用户选择分支名称,然后运行jobNope。只需添加git repo,分支名称就可以在开始构建之前使用。我尝试了,但没有工作属性([parameters([gitParameter])(分支:'',分支筛选器:'源/(.*)),defaultValue:'master',description:'',name:'BRANCH',quickFilterEnabled:false,selectedValue:'NONE',sortMode:'NONE',tagFilter:'*',type:'PT_BRANCH')]])节点{git branch:“${params.branch}”,url:'https://github.com/jenkinsci/git-parameter-plugin.git“}
是否有任何东西反对只使用输入
步骤(除了您的要求“我需要使用活动参数”)?