jenkins + statistics 实现代码统计


git 的statistics统计分页,待页面

简书地址

一个不错的代码统计插件statistics

安装statistics

需要先在收集代码的服务器上搭建statistics,具体步骤上面链接有。
我是centos系统,因此只需一句命令:

yum install gitstats

jenkins配置

#执行脚本
echo "git stats start"
/opt/auto-deploy-scripts/code_statistics.sh questionnaire master
echo "git stats end"
echo "review address:http://10.138.46.76:8888/questionnaire/"

收集脚本code_statistics.sh

[root@1169CKT questionnaire]# vi /opt/auto-deploy-scripts/code_statistics.sh

#!/bin/bash

name=$1
branch=$2

if [ name == ""  ] ;then

    echo "project name is null"
    exit 5

else

    if [ branch == ""  ] ;then

    branch = master

    fi
    echo "Deploy ${branch} of ${name} project !"

    cd /opt/chuangke/gitstats/projects/${name}/

    git pull
    git checkout ${branch}

    cd /opt/chuangke/gitstats/gitstats/

    rm -rf /opt/chuangke/gitstats/result/${name}/*

    ./gitstats /opt/chuangke/gitstats/projects/${name} /opt/chuangke/gitstats/result/${name}/

   echo "Deploy success!"

fi

关于脚本的一点解释

  • 两个参数,第一个是项目名,第二个是分支名
  • /opt/chuangke/gitstats/projects/${name}/目录是$name项目从git库pull下来的目录,也就是要统计的目标项目。
  • /opt/chuangke/gitstats/result/${name}/目录是$name项目统计完以后生成的静态文件目录,也是nginx要访问的目录。
  • gitstats项目的目录下执行gitstats脚本的第一个参数是要统计的项目,第二个参数是统计文件存放的目录

nginx 配置

server {
        listen       8888;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        client_max_body_size    100m;
    
        location /questionnaire {
            alias  /opt/chuangke/gitstats/result/questionnaire;
        }

        location /portal {
            alias  /opt/chuangke/gitstats/result/Portal;
        }

        location /portalmanage {
            alias  /opt/chuangke/gitstats/result/portalmanage;
        }

        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

来个截图
gitstats1

gitstats2

gitstats3

注意

配置的nginx要能在浏览器访问,需要保证centos的防火墙配置哟。

开启端口


[root@centos7 ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

查询端口号80 是否开启:

[root@centos7 ~]# firewall-cmd --query-port=80/tcp

重启防火墙:

[root@centos7 ~]# firewall-cmd --reload

查询有哪些端口是开启的:

[root@centos7 ~]# firewall-cmd --list-port

评论
  目录