jenkins简单入门使用(WEB)

一 安装

首先保证系统中已经安装了jdk,最好是jdk1.5以上。php

http://jenkins-ci.org/  下载本机环境相对应包安装。git

在浏览器中输入 http://localhost:8080 访问。shell


我本机是安装在虚拟机CentOS上面。
vim

安装jenkins浏览器

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins

安装GITbash

yum update
yum -y install zlib-devel openssl-devel perl cpio expat-devel gettext-devel 
yum install curl-devel
yum install autoconf 

wget http://git-core.googlecode.com/files/git-1.8.3.2.tar.gz
tar xzvf git-1.8.3.2.tar.gz 
cd git-1.8.3.2 
autoconf 
./configure --with-curl=/opt/git 
make 
make install

修改etc/passwd文件,让jenkins用户有ssh操做权限。
服务器

jenkins:x:496:496:Jenkins Continuous Integration Server:/var/lib/jenkins:/bin/bash

使用jenkins用户ssh

su jenkins

而后 生成ssh-key (是在jenkens这个用户的根目录)curl

ssh-keygen -t rsa -C "youremail@example.com"


在浏览器中输入http://你的IP:8080 google


二 使用

系统管理--管理插件--可选插件   搜索git

安装Git plugin和GitHub plugin插件

进入"系统管理->系统设置"设置Jenkins的相关参数。(这里只用设置GIT)

设置GIT


配置ssh key

Credentials--Global credentials (unrestricted)--Add Credentials (让Jenkins自动找key)


新建项目


配置项目  Repository URL输入Repository的Git地址(代码地址,Credentials 选择上文加jenkins。


填写shell命令

ls -la //列出文件
rsync -auv --delete --exclude=/.git --exclude-from=./deployignore 
//rsync同步  删除 过滤/.git   设置过滤文件 ./deployignore 
./ root@192.168.97.243:/root/www/
// 用ssh登录 目标服务器
ssh root@192.168.97.243 ls -la /root/www/
//列出文件

设置下更新目标的的服务器(也就是192.168.97.243),使他支持ssh

vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

安装rsync

yum -y install rsync

新建ssh目录

mkdir .ssh
chmod 755 .ssh/

而后在.ssh目录下建立authorized_keys 文件

touch authorized_keys
chmod 600 authorized_keys

把jenkins的key保存在这个文件。

点击构建,显示为蓝色就表示成功,红色为错误。

相关文章
相关标签/搜索