Jenkins 参数化构建 ¶
创建参数化构建视图(练习用) ¶
参数化构建参数 ¶
1. 新建任务 ¶
2. 编写 Jenkinsfile ¶
1. 添加 选项参数、字符串参数
properties([
parameters([
choice(name: 'architecture', choices: ['amd64', 'arm64'], description: '请选择 amd64 or arm64?'),
string(name: 'user', defaultValue: 'aaa', description: '安装包发给谁?'),
booleanParam(name: 'runTests', defaultValue: true, description: '是否运行测试?'),
text(name: 'releaseNotes', defaultValue: '', description: '发布说明')
])
])
动态参数化构建参数 ¶
安装插件: Active Choices 插件
properties([
parameters([
choice(name: 'build_datarc_install', choices: ['1-deploy', '2-update'], description: '请选择部署包 or 升级包?'),
choice(name: 'architecture', choices: ['amd64', 'arm64'], description: '请选择 amd64 or arm64?'),
[$class: "CascadeChoiceParameter",
choiceType: "PT_SINGLE_SELECT",
description: "查看镜像版本",
filterLength: 1,
filterable: false,
name: "version",
randomName: "test1",
referencedParameters: "build_datarc_install,architecture",
sandbox: true,
script: [
$class: "GroovyScript",
script: [
classpath: [],
script:
''' def getImageTags() {
def gettags = ['/bin/bash', '-c', "bash /opt/install/get_docker_tag.sh '${build_datarc_install}' '${architecture}' core "].execute()
return gettags.text.readLines()
}
def choices = getImageTags()
return choices
'''
]
]
],
[$class: "CascadeChoiceParameter",
choiceType: "PT_SINGLE_SELECT",
description: "查看go-ws镜像版本",
filterLength: 1,
filterable: false,
name: "ws_version",
randomName: "test2",
referencedParameters: "build_datarc_install,architecture",
sandbox: true,
script: [
$class: "GroovyScript",
script: [
classpath: [],
script:
''' def getImageTags() {
def gettags = ['/bin/bash', '-c', "bash /opt/install/get_docker_tag.sh '${build_datarc_install}' '${architecture}' go-ws "].execute()
return gettags.text.readLines()
}
def choices = getImageTags()
return choices
'''
]
]
],
string(name: 'user', defaultValue: '111', description: '安装包发给谁?'),
])
])