Jenkins(五)参数化构建

一、基础参数化构建

步骤:新建一个自由风格的软件项目 -> 配置参数化构建过程 -> 调用参数 -> 应用并保存项目 -> 使用参数构建 -> 查看构建结果

 

 

1.1 常用的参数化构建过程

1.1.1 String 字符参数

1.1.2 Text 文本参数

1.1.3 Choice 选项参数

使用 Choice 选项参数来参数化构建过程,在立即构建时则可以下拉选择参数来进行构建

 

1.2 脚本中使用参数

1.2.1 git 等源码管理时调用参数的格式为 ${param}

1.2.2 shell 脚本中调用参数格式为 $param

1.2.3 windows 批处理命令中调用参数格式为 %param%

1.3 示例

二、Extended Choice Parameter 插件

2.1 安装

在插件管理中安装 Extended Choice Parameter 插件,安装成功后进入项目查看 “参数化构建过程” 中多了一项 Extended Choice Parameter。

2.2 使用

2.2.1 Basic Paramter Types(常用)

1. 参数值直接写在 Jenkins 中

2. 从配置文件中读取参数

# d:\test.properties 文件内容为

user=user1,user2,user3

2.2.2 Multi-level Parameter Types

2.2.3 JSON Parameter Type

三、Git Parameter 插件

3.1 安装

在插件管理中安装 Git Parameter 插件,安装成功后进入项目查看 “参数化构建过程” 中多了一项 Git Parameter。通过 Git Parameter 参数可以直接获取到 git 的tag、branch 等

3.2 使用

3.2.1 git 仓库准备

# git 仓库创建多个分支
git clone https://github.com/gancaoer/demo.git cd demo git branch test git checkout test type nul>test.html git add . git commit -m "test" git push origin master git push origin test git branch

注:jenkins 所在机器上需要安装 git 服务

3.2.2 配置 git 参数

3.2.3 从 git 仓库获取指定分支

3.2.4 参数化构建

使用 Build with Parameters 立即构建时将会获取到 git  仓库的分支:origin/master、origin/test

 

posted @ 2020-09-26 08:52  芒果日记  阅读(1239)  评论(0编辑  收藏  举报