jenkins 搭建过程
jenkins 做什么
Jenkins 是持续集成中绕不过的一个服务、用作基于 gitlab 的发布系统 开发提交代码到 gitlab,通过 Jenkins 拉取代码 发布到测试环境
环境需求
- Java
- nginx
官网下载最新版 war 包,采用 Java 命令直接启动是最简便快捷的方式
java -jar jenkins.war --httpport=8000
如何自定义 Jenkins_Home 目录
Jenkins 启动默认路径为 ~/.jenkins ,如何改变此目录呢?
- 环境变量增加
JENKINS_HOME路径
vim /etc/profile
JENKINS_HOME=/opt/jenkins
source /etc/profile
然后再启动即可
java -jar jenkin.war --httpport=8000
通过 Nginx 进行反向代理
vim jenkins.conf
upstream jenkins {
server 127.0.0.1:8000; # jenkins ip and port
}
server {
listen 443 ssl; # https
server_name ci.xxxx.com;
ssl_certificate vhost/xxxx.com.crt;
ssl_certificate_key vhost/xxxx.com.key;
#this is the jenkins web root directory (mentioned in the /etc/default/jenkins file)
root /opt/jenkins/war/;
#access_log /var/log/nginx/jenkins/access.log;
#error_log /var/log/nginx/jenkins/error.log;
ignore_invalid_headers off; #pass through headers from Jenkins which are considered invalid by Nginx server.
location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
#rewrite all static files into requests to the root
#E.g /static/12345678/css/something.css will become /css/something.css
rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
}
location /userContent {
#have nginx handle all the static requests to the userContent folder files
#note : This is the $JENKINS_HOME dir
root /var/lib/jenkins/;
if (!-f $request_filename){
#this file does not exist, might be a directory or a /**view** url
rewrite (.*) /$1 last;
break;
}
sendfile on;
}
location / {
sendfile off;
proxy_pass http://jenkins;
proxy_redirect default;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_max_temp_file_size 0;
#this is the maximum upload size
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffering off;
proxy_request_buffering off; # Required for HTTP CLI commands in Jenkins > 2.54
proxy_set_header Connection ""; # Clear for keepalive
# 如果用到 blue ocean 插件则配置以下条目
if ($request_uri ~* "/blue(/.*)") {
proxy_pass http://jenkins/blue$1;
break;
}
}
}
启动后,打开浏览器进行初始化安装插件等