分享

jenkins学习10-参数化构建(构建git仓库分支)

 上海悠悠 2021-05-27

前言

当我们的自动化项目越来越多的时候,在代码仓库会提交不同的分支来管理,在用jenkins来构建的时候,我们希望能通过参数化构建git仓库的分支。

Git Parameter插件

先下载 Git Parameter 插件,系统管理-插件管理-搜索:Git Parameter 下载安装

安装完成

参数化构建工程

General-参数化构建过程-添加参数-Git Parameter,

填写 Git Parameter 参数配置

  • Name 自定义参数名称
  • Description 描述
  • Paramert Type 参数类型,可选 Tag 、Branch 、Branch or Tag、Revision、Pull Request
  • Default Value 默认值

指定分支引用上面的变量:$branch

参数化构建

保存成功后,在job列表页,构建的时候,可以选择- Build with Parameters

接着会自动加载出项目的所有分支,可供选择

勾选其中一个分支就可以构建了,构建完成后可以看控制台输出日志

Started by user admin Running as SYSTEM Building in workspace /var/jenkins_home/workspace/pytest_demo using credential c7f48895-1166-45c5-a066-582c7ffa1111 > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://github.com/yoyoketang/pytest_jenkins_demo.git # timeout=10 Fetching upstream changes from https://github.com/yoyoketang/pytest_jenkins_demo.git > git --version # timeout=10 using GIT_ASKPASS to set credentials > git fetch --tags --progress -- https://github.com/yoyoketang/pytest_jenkins_demo.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse refs/remotes/origin/yoyoketang^{commit} # timeout=10 > git rev-parse refs/remotes/origin/origin/yoyoketang^{commit} # timeout=10 Checking out Revision 2932c8cfff11ed08d5c44d207d8b72d83917fb63 (refs/remotes/origin/yoyoketang) > git config core.sparsecheckout # timeout=10 > git checkout -f 2932c8cfff11ed08d5c44d207d8b72d83917fb63 # timeout=10 Commit message: "新增yoyoketang"

从日志看出,构建时候拉取到的分支是:/remotes/origin/yoyoketang

2020年第三期《python接口自动化+测试开发》课程,4月5号开学(火热报名中!)

本期上课时间:4月5号-6月27号,每周六、周日晚上20:30-22:30

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多