欢迎扫码,加作者微信

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
目录

运营需要亿点资金维持,您的支持,是小白龙创作的动力!!!

昵称
留言
赞赏金额
暂无评论,欢迎留下你的评论
暂无评论,欢迎留下你的评论