在Jenkins 界面上配置参数
1. 新增字符串参数,参数名为Branch, 默认值为feature/f250907, 描述可以设置你想要的说明等等

2. 新增选项参数

3. 配置pipeline scripts
在脚本中添加参数,确保参数名和默认值和界面上配置的一样
parameters {
string(name:'Branch', defaultValue:'feature/f250907')
choice(name:'Run_Env', choices: ['dev', 'test', 'prod'])
}
替换分支参数,使得可动态获取给的build 分支。可以添加echo语句查看验证是否获得参数值。
stage("clone source code") {
steps {
echo "target branch is: ${params.Branch}"
echo "target run env is: ${params.Run_Env}"
git branch: "${params.Branch}", credentialsId: 'jenkins-container', url: 'git@gitee.com:joyce-zhou/python-automation-testing.git'
echo "clone source code - successfuly"
}
}
其他类型的参数类似,用上面的方法配置,界面创建好后添加到对应的pipeline 脚本或者Jenkinsfile中。
pipeline build with paramters 运行结果:

2822

被折叠的 条评论
为什么被折叠?



