Gitlab Merge Request Builder Pluginの設定
インストール環境
- Jenkins ver 2.102
- Git client plugin ver 2.7.0
- Git plugin ver 3.7.0
- Gitlab Merge Request Builder ver 1.2.4
gitlabにjenkinsユーザーを追加
- Ensure that a Jenkins user exists within Gitlab and has access to the repository.
- For Gitlab version < 8.4.X: ensure that the user has Reporter level access to the project.
- For Gitlab version >= 8.4.X: ensure that the user has Developer level access to the project.
- Please note that if you would like to use the Auto-merge feature Jenkins needs to have Developer access to the project.
Jenkinsへプラグインをインストールする
- Install the plugin in Jenkins.
- The plugin is hosted on the Jenkins Plugin repository
- Go to Jenkins -> Manage Plugins -> Available
- Search for Gitlab Merge Request Builder
- And install it Ensure you restart Jenkins
- Go to Manage Jenkins -> Configure System -> Gitlab Merge Request Builder
- Set the Gitlab Host URL to the base URL of your Gitlab server
- Set your Jenkins Username for the Jenkins user (defaults to jenkins)
- Set your Jenkins API Token for the Jenkins user. This can be found by logging * into Gitlab as Jenkins and going to the user profile section.
- Set/change any of the other available parameters as necessary. If you host * Gitlab over an SSL connection you may want to enable ignoring certificate errors.
- Save to preserve your changes.
- Go to Manage Jenkins -> Configure Global Security and set Markup Formatter to * Safe HTML. It will make Jenkins display links in build history properly.
JenkinsのJobを作成する
- Create a new job by going to New Job
- Set the Project Name
- Feel free to specify the GitHub Project URL as the URL for the Gitlab project (if you have the GitHub plugin installed)
Job Notifications
Jenkins ver 2以降では利用する環境変数をパラメータとして設定しないと参照できない?
- ビルドのパラメータ化をチェック
- パラメータの追加 から テキストを選択
- gitlabSourceBranch と gitlabTargetBranch の二つを追加する
ソースコード管理
- Gitを選択して、リポジトリURLと「高度な設定...」内にある名称に origin と設定
- For merge requests from forked repositories add another repository with Repository URL ${gitlabSourceRepository} and in Advanced set Name to ${gitlabSourceName}
- In Branch Specifier enter refs/remotes/origin/${gitlabSourceBranch} or for merge requests from forked repositories enter ${gitlabSourceName}/${gitlabSourceBranch}
追加処理
- Click the Add drop down button and the Merge before build item
- Specify the name of the repository as origin (if origin corresponds to Gitlab) * and enter the Branch to merge to as ${gitlabTargetBranch}
- Ensure Prune stale remote-tracking branches is not added
ビルド・トリガ
- Check the Gitlab Merge Requests Builder
- Enter the Gitlab Project Path, this might be something like your_group/your_project for Gitlab URL http://git.tld/your_group/your_project
- The Target Branch Regex may be configured to whitelist this job for certain target branches. If left empty, every valid merge request for the configured project path will trigger this job.
- The Use HTTP(S) URL checkbox should be used if you want Jenkins to clone/fetch using HTTP(S) instead of SSH.
- Configure any other pre build, build or post build actions as necessary
- Save to preserve your changes