jenkins配置
下载载最新的版本, 官方网站http://jenkins-ci.org/#安装依赖apt-get install daemon#安装jenkinsdpkg -i jenkins_1.635_all.deb #修改jenkins 默认监听端口,默认监听 8080 端口vim /etc/default/jenkinsHTTP_PORT=9000#重新 jenkins 服务/etc/init
·
下载载最新的版本, 官方网站http://jenkins-ci.org/
#安装依赖
apt-get install daemon
#安装jenkins
dpkg -i jenkins_1.635_all.deb
#修改jenkins 默认监听端口, 默认监听 8080 端口
vim /etc/default/jenkins
HTTP_PORT=9000
#重新 jenkins 服务
/etc/init.d/jenkins restart
#也可以将下载的war包放入tomcat中运行
设置用户和权限
安装插件
进入插件管理安装常用的插件,Gerrit Trigger,GitLab Plugin, GIT plugin, Github Plugin, Multiple SCMs, Git Client Plugin
新建Git项目
为项目添加认证信息,ssh协议获取的Git仓库, Credentials
选用SSH Username with private key
方式
http协议, Credentials
选用Username with password
方式
添加shell脚本
echo "hello world"
if [ -e "hello.c" ] ; then
g++ hello.c -o hello --std=c++11
echo "complie hello.c ok!"
else
echo "hello.c not exist"
fi
./hello
编辑hello.c文件,并提交
#include <iostream>
#include <functional>
int main(){
auto func1 = [](int i) { return i+4; };
std::cout << "func1: " << func1(6) << '\n';
std::function<int(int)> func2 = [](int i) { return i+4; };
std::cout << "func2: " << func2(6) << '\n';
}
构建输出结果
配置gerrit Trigger
1. 生成SSH Key
#切换到jenkins用户,再生成密钥
sudo su jenkins
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
#配置jenkins用户git信息
git config --global user.name "jenkins"
git config --global user.email "email"
2. 添加jenkins用户, 并赋予管理员权限
#切换到gerrit用户
su gerrit
#添加jenkins账号
htpasswd -b ./review_site/etc/passwd jenkins yourpassword
#网页登录,添加邮箱(需要与git邮箱一致)和SSH公钥, 并测试ssh能否访问
git clone ssh://jenkins@localhost:29418/hello1
3. 赋予jenkins用户Stream Events
权限
否则会出现User jenkins has no capability to connect to Gerrit event stream
错误
#管理员登录gerrit
Projects->List->All-Projects
Projects->Access -> > Edit
#添加 jenkins 用户到 ‘Non-Interactive Users’ 组
Global Capabilities->Stream Events 点击 Non-Interactive Users
#分支权限
Reference: refs/*
Read: ALLOW for Non-Interactive Users
Reference: refs/heads/*
Label Code-Review: -1, +1 for Non-Interactive Users
Label Verified: -1, +1 for Non-Interactive Users
4. 配置gerrit Trigger参数
Manage Jenkins -> Gerrit Trigger
Fronted URL 是代理服务器地址, 点击Test Connection
确保连接gerrit服务器正确
自动验证
查看gerrit服务器状态
编辑项目配置, 在Trigger on 可以添加要触发的事件
- Patch set created: Trigger when a new change or patch set is uploaded (default). 当补丁集被创建时触发,开发者的代码需要先提交到refs/for/master分支上,补丁集被创建保存在
refs/changes/*
命名空间下. - Draft published: Trigger when a draft change or patch set is published (default, if available in Gerrit version)
- Change abandoned: Trigger when a change is abandoned
- Change merged: Trigger when a change is merged/submitted
- Change restored: Trigger when a change is restored
- Comment added: Trigger when a review comment is left with the indicated vote category and value
- Reference updated: Trigger when a reference (e.g., branch or tag) is updated
添加触发事件,这里添加了Draft published和Change merged事件
当提交审查代码后,发现真的触发了构建任务
gerrit也被jenkins验证通过
测试的时候可以通过Query and Trigger Gerrit Patches 来手动触发事件.
参照
更多推荐
已为社区贡献5条内容
所有评论(0)