jenkins學習10-參數化構建(構建git倉庫分支)


前言

當我們的自動化項目越來越多的時候,在代碼倉庫會提交不同的分支來管理,在用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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM