在jenkins shell脚本中获取提交者信息

jenkins中可以传递给shell脚本的变量:http://YOUR_JENKINS_ADDRESS/env-vars.html/ 从这个地址可以看到。
本来想取GIT_COMMITTER_NAME、GIT_AUTHOR_NAME就是取不到,咱也不敢说为什么,也不敢问。

变通路子,从拉下来的git仓库目录里执行git命令查。
https://git-scm.com/docs/git-show 这里可以看到git show支持的参数。

#/bin/bash
username=`git show -s --pretty=%an`
pushtime=`git show -s --pretty=%aD`
echo "分支:" ${GIT_BRANCH} # 这个直接从jenkins变量中取。
echo "推送者:" $username
echo "时间:" $pushtime

这样才算取到提交者信息。

nginx中关于error_page配置参数介绍

# 当访问文件不存在返回404状态码,由nginx内部重定向返回/404.html的内容。

server {    
.

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html; # 支持多个状态码重定向到同一个地址。
.
}

# 如果写一个外部地址,则会发生302跳转。

server {    
.

    error_page 404 https://www.rootop.org;
    
    #error_page 404 = @fallback; # 这里也可以写内部重定向(location @name 命名位置)
    #location @fallback {
    #    proxy_pass http://backend;
    #}
.
}

# 关于location @name 资料看官方:http://nginx.org/en/docs/http/ngx_http_core_module.html#location
The “@” prefix defines a named location.
Such a location is not used for a regular request processing, but instead used for request redirection.
They cannot be nested, and cannot contain nested locations.

#当nginx配置为FastCGI(如lnmp)发生500错误时进行跳转的时候添加如下:

error_page 500 https://www.rootop.org/500.jpg;

会发现浏览器还是直接显示了500错误,并没有跳转到500.jpg(302)。

这就需要在fastcgi部分添加一行配置 fastcgi_intercept_errors on;

location ~ .*\.(php|php5)?$
{
    try_files $uri =404;
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_intercept_errors on;
}

参数作用参考:http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_intercept_errors
意思就是fastcgi服务器发生大于等于300的错误码时,交由nginx的error_page指令处理后返给客户端。
所以在lnmp环境中,如果配置了error_page指令没有效果,就去查有没有这个参数。

nginx中try_files作用及location @作用

# nginx 配置文件:

server {

    listen 80;
    server_name  api.xxx.com;

    root /mnt/try;

    location / {
        add_header  Content-Type 'text/html; charset=utf-8';
        #echo $uri;
        try_files $uri @default;
    }

    location @default {
        root /mnt/default;
    }
}

location @xxx解释:定义一个location段,不能被外部请求所访问,只能用于nginx内部配置指令使用,比如 try_files、error_page。
$uri解释:URI代表资源的名称

浏览器访问 http://api.xxx.com/abc/index.html 时,当前的$uri值为/abc/index.html

可以通过编译nginx参数--add-module添加第三方echo模块打印$uri

echo模块地址:https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz

# try_files作用:
try_files会先尝试去/mnt/try目录下找abc目录下的index.html,如果有,直接返回,没有的话则跳转到@default部分(内部重定向)。
在default部分会去/mnt/default目录下找abc目录下的index.html,有,直接返回,没有就返回404错误。

try_files可以理解为实现rewrite的作用。

package golang.org/x/sys/unix: unrecognized import path “golang.org/x/sys/unix” (https fetch: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

root@venus:~/桌面/go_project/process# go get -t golang.org/x/sys/unix
package golang.org/x/sys/unix: unrecognized import path "golang.org/x/sys/unix" (https fetch: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

在用go get安装包时出错,这个是因为被墙了(不明白为什么)。

这里通过配置代理后再安装需要的包

# shell中设置http、https代理

root@venus:~/桌面/go_project/process# export http_proxy=http://127.0.0.1:1111
root@venus:~/桌面/go_project/process# export https_proxy=http://127.0.0.1:1111

# 忽略某个地址走代理,多个用逗号隔开,支持域名或ip

root@venus:~/桌面/go_project/process# no_proxy="www.rootop.org"

127.0.0.1:1111 是我本地shadowsocks-Qt5客户端监听的地址。


在shell中通过设置http_proxy和https_proxy两个变量,可以提供给curl、wget之类的命令自动走代理。同样go get时也会自动找这俩变量实现代理。
再次安装解决。