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保存在這個文件。

點擊構建,顯示爲藍色就表示成功,紅色爲錯誤。

相關文章
相關標籤/搜索