bitbucket + git + jenkins + nginx 实现产品需求文档上传展示

需求:

  1. 产品需求文档快速上传
  2. 产品需求文档有上传记录可查
  3. 产品需求文档在网络上展示

(一):使用 Bitbucket 来存放产品文档

创建一个 PRODUCT 项目,按产品人员名字来区分各个产品经理的需求

创建,Jenkins 用户,配置 Personal access token


注意,Bitbucket 的项目需要给予 Jenkins 用户管理权限

(二): 搭建 Jenkins

这里使用的版本为
1)Jenkins 2.287
2)java version "1.8.0_191"
3)Apache Tomcat/8.5.31

Jenkins 需要安装的插件为:Bitbucket Server Integration

创建两个凭证

  1. 用来连接 Bitbucket
  2. Jenkins Personal access token

系统配置


注意:Personal access token 使用上面的 bitbucket 配置的 Jenkins Personal access token

配置 /root/.netrc 避免下载 Bitbucket 代码时输入密码

创建项目


TARGET="/usr/local/nginx/html/prototype/${JOB_NAME}"

source /etc/profile

mkdir -p ${TARGET} && chmod o+rx ${TARGET}

rsync -rltD --chmod=Dugo=rwx,Fugo=rw --delete ${WORKSPACE}/ ${TARGET}/

(三): 手动在 Bitbucket 上加上 webhook



url 为:http://8.135.33.221:8888/jenkins/bitbucket-server-webhook/trigger

(四): 服务器上安装 Nginx

nginx 编译安装在 /usr/local/nginx/ 下,在 html 目录下创建 prototype 来保存产品文档

nginx.conf 的配置为

worker_processes  1;

events {
    use epoll;
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 100m;

    sendfile           on;
    keepalive_timeout  65;
 
    server_tokens off;

    access_log off;

    gzip  on;
    gzip_proxied any;
    gzip_disable "MSIE [1-6].";
    gzip_min_length  512;
    gzip_buffers     4 8k;
    gzip_comp_level 4;
    gzip_types       text/plain text/css application/x-javascript application/javascript application/xml application/json;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


    }

    include vhost/*.conf;
  
}

(五): 测试




注意,这里一次 push 构建一次,若出现多次 commit,只有一次 push,则会显示对最后一次的 commit 进行构建


这里可能会出现浏览器缓存问题,导致没有及时显示

(六):遇到的问题

可能会遇到 Bitbucket - did not accept the request


原因:
服务器上 /root/.netrc 文件的中的用户对项目没有读写权限,增加读写权限后即可。

posted @ 2021-04-12 11:34  klvchen  阅读(102)  评论(0编辑  收藏  举报