JenKins入门教程
2022-05-27 18:50:13
2025-02-05 01:52:51
安装 jenkins
shell
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
shell
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
shell
sudo yum install jenkins
安装 Java
shell
sudo yum install java
启动服务
shell
service jenkins start
配置 nginx 访问(可以不设置)
javascript
server {
listen 80; # Listen on port 80 for IPv4 requests
server_name www.wangzhi.com;
access_log /var/log/nginx/jenkins_access.log;
error_log /var/log/nginx/jenkins_error.log;
location ~ ^/static/[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]\/(.*)$ {
#E.g /static/12345678/css/something.css will become /css/something.css
rewrite "^/static/[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]\/(.*)" /$1 last;
}
location @jenkins {
sendfile off;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
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_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location / {
root /var/cache/jenkins/war/;
try_files $uri @jenkins;
}
}
升级站点url
http
http://mirror.xmission.com/jenkins/updates/update-center.json
安装 Generic Webhook Trigger Plugin 插件
勾选 Generic Webhook Trigger Plugin ,添加 Token(用于触发远程仓库 web hooks 的标识)
http
http://:<ip>:<端口>/generic-webhook-trgger/invoke?token=<token>
安装 NodeJS 插件
构建环境
Provide Node & npm bin/ folder to PATH 配置一下
执行 shell
shell
#!/bin/sh
npm install
rm -rf ./打包文件夹/*
npm run build
rm -rf /www/wwwroot/网站/*
cp -rf ./dist/* /www/wwwroot/网站
修改 Jenkins 以 root 用户运行
修改 Jenkins 配置文件
shell
vim /etc/sysconfig/jenkins
\$JENKINS_USER="root"
修改Jenkins
相关文件夹用户权限
shell
chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins
问题处理
Public key for jenkins-2.237-1.1.noarch.rpm is not installed
shell
cd /etc/pki/rpm-gpg
shell
wget http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6
shell
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
卸载 Jenkins
shell
service jenkins stop
shell
yum clean all
shell
yum -y remove jenkins
重启 Jenkins
命令行
shell
systemctl restart jenkins
域名
shell
域名/restart
目录