jenkins - Jenkinsfile 主动选择参数插件(动态 git 分支名称)
问题描述
我需要在 jenkinsfile 中使用 Active Choices Reactive Parameter 和下面的 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('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}
如何在我的 jenkinsfile 中定义这个参数?
我使用了以下代码:
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'
]
]],
])
])
解决方案
推荐阅读
- java - 映射 UML 图到 Java 代码转换
- javascript - 字符串匹配函数返回一个数组,但如果转换为数字,则返回匹配的数字
- c++ - 我遇到了 C++“参数太多”警告的问题
- python - SQLAlchemy 有最大数量的关系?
- c++ - CPP 中的 ++ 运算符是否对 char 有任何重载?
- python - 为列表列表中的每个列表映射一个函数
- python - 如何让 Pandas 从下一行开始在新列中创建 sumsum?
- mfc - MFC CImageList DeleteImageList() vs Remove()
- android - Android studio 线性布局问题:我应该如何在没有嵌套权重的情况下布局我的?
- python - 16位PNG的像素值20930不应该是灰色阴影吗?