需求

项目需要在jenkins自动发布中加入version.html来跟踪项目发布的版本信息,需要获取到jira中当前sprint的名字,和一个sprint中的发布次数(我这里用文件把次数存起来的傻方法来计数的)。

shell初学者脚本写的很烂,还望大神们指教。 - -!

方法

直接使用curl 向jira发送get请求,将返回的json通过jq过滤出来存入currentSprint.txt文件中。

curl -u JiraUserName:Password -X GET -H "Content-Type: application/json" \
'http://jira.jintelhealth.com/rest/greenhopper/1.0/sprintquery/13?includeFutureSprints=true&includeHistoricSprints=false' \
| /usr/bin/jq '.sprints[] | select(.name | contains("PD")) | select(.state == "ACTIVE") | .name'|sed 's/\"//g'> currentSprint.txt

注意:

这里在linux下需要安装 jq linux json格式化工具

添加epel源

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
yum repolist
yum install jq

总结

读取文件 $(cat file.txt)

除去name中的双引号 name'|sed 's/"//g'

shell中数字求和 echo $(( 1 + 2 )) => 3

代码

############PD-2375#############################

cd $PWD

if [ ! -f "${PWD}/LastBuildSprint.txt" ];then
echo 0 > ${PWD}/LastBuildSprint.txt
fi curl -u JiraUserName:Password -X GET -H "Content-Type: application/json" \
'http://jira.jintelhealth.com/rest/greenhopper/1.0/sprintquery/13?includeFutureSprints=true&includeHistoricSprints=false' \
| /usr/bin/jq '.sprints[] | select(.name | contains("PD")) | select(.state == "ACTIVE") | .name'|sed 's/\"//g'> currentSprint.txt if [ "$(cat ./currentSprint.txt)" == "$(cat ./LastBuildSprint.txt)" ];
then
echo $(($(cat ./SprintBuildNumber.txt)+1)) > ./SprintBuildNumber.txt
else
echo 1 > ${PWD}/SprintBuildNumber.txt
fi cp -rf ${PWD}/currentSprint.txt ${PWD}/LastBuildSprint.txt ###########generate version.html#################
rm -f ${PWD}/version.html
echo "remove successfully!" {
echo "<html>"
echo "<head>"
echo "<title>Analytics: Version</title>"
echo "</head>"
echo "<body bgcolor="#ffffff">"
echo "<span id="analytics_version">Version: $(cat ./currentSprint.txt) B$(cat ./SprintBuildNumber.txt)</span>"
echo "<br /><br />"
echo "<span id="tag">BUILD INFO: Jenkins Build ${BUILD_NUMBER} `date`</span>"
echo "<br /><br />"
echo "<span id="commit">COMMIT SHA: ${GIT_COMMIT}</span>"
echo "<br /><br />"
echo "</body></html>"
}>> version.html ############PD-2375#############################

脚本参考自 http://kagarlickij.com/get-active-jira-sprint-name-cli/

jenkins里面使用shell 获取jira的sprint信息的更多相关文章

  1. Bash Shell 获取进程 PID

    转载地址:http://weyo.me/pages/techs/linux-get-pid/ 导读 Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运 ...

  2. 用C++和shell获取本机CPU、网卡IO、内存、磁盘等的基本信息

    用C++和shell获取本机CPU.网卡.内存.磁盘等的基本信息: 由于对C++相关的函数没多少了解,但是觉得用shell反而相对简单一些: 一.shell脚本,用来辅助C++获取主机的资源使用信息 ...

  3. linux中用shell获取昨天、明天或多天前的日期

    linux中用shell获取昨天.明天或多天前的日期 时间 -- :: BlogJava-专家区 原文 http://www.blogjava.net/xzclog/archive/2015/12/0 ...

  4. linux中用shell获取时间,日期

    linux中用shell获取昨天.明天或多天前的日期:在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:# -d, --date=STRING display time d ...

  5. 这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script

    这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script ##转载注明出处:http://www.cnblogs.com/wade-xu/p/4378224.html ...

  6. shell 获取网关 以及修改ip 启用网卡

    shell 获取网关 以及修改ip 启用网卡 #!/bin/bash #autho freefei #script is a init computer eth #data 2014 10 09 19 ...

  7. python执行shell获取硬件参数写入mysql

    最近要获取服务器各种参数,包括cpu.内存.磁盘.型号等信息.试用了Hyperic HQ.Nagios和Snmp,它们功能都挺强大的,但是于需求不是太符,亦或者太heavy. 于是乎想到用python ...

  8. Shell获取格式化日期

    Shell获取格式化日期 shell date 获取昨天日期 使用date -d 选项: date +"%Y%m%d" -d "+n days" 今天的后n天日 ...

  9. Shell获取文件的文件名和扩展名的例子

    这篇文章主要介绍了Shell获取文件的文件名和扩展名的例子,简明版的代码实例,看了就懂,需要的朋友可以参考下 basename example.tar.gz .tar.gz # => examp ...

随机推荐

  1. Can't create new folder in windows7

    First, please use System File Checker tool to troubleshoot(诊断) this issue. If the issue persists, im ...

  2. appium 获取app的应用包名package和activity

    第一种,使用sdk自带的工具aapt,在sdk\builds-tools\目录下,切换到aapt所在目录 命令:aapt dump badging app的路径,运行后的结果中以下两行分别是应用包名p ...

  3. ZT Factory Pattern

    图中的虚线箭头表示依赖关系

  4. csr867x开发日记——常用软件工具介绍

    xIDE xIDE开发环境(编译器)可以被用于以下操作 查看代码 构建新应用 调试 运行 重新配置 修改 Universal Front End 通用前端 通用前端(UFE)工具用于配置DSP,ADK ...

  5. [转]Activitys, Threads, & Memory Leaks

    转自:http://www.androiddesignpatterns.com/2013/04/activitys-threads-memory-leaks.html http://www.cnblo ...

  6. iOS动画的要素:CALayer维护数据模型和图片,沟通了CPU和GPU--视图中与图形绘制相关的功能

    1)iOS动画的模型:三层树模型: CALayer维护数据模型和图片,沟通了CPU和GPU:数据模型和图片本尊有CPU生成和维护:图片动画由GPU合成和呈现: https://developer.ap ...

  7. CF1063A Oh Those Palindromes

    嘟嘟嘟 只要将每一种字母放一块输出就行了. 证明1:比如 1 2 3 4 5 6,那么这个序列对答案的贡献分别是1和5,2和4 ,3和6……如果重新排列成x x x x o o,会发现对        ...

  8. PHP单链表的基本操作

    链表的实现 数据结构第一个就是链表了,链表分为两种有直接的数组形式的顺序链,这里不讨论,什么array_push(),array_pop(),函数基本能满足日常的需求,但报告老板,我就是想装个X 上代 ...

  9. Kali-linux目录加密

    在Kali中提供了一个目录加密工具TrueCrypt.该工具是一款开源的绿色加密卷加密软件,不需要生成任何文件即可在硬盘上建立虚拟磁盘.用户可以按照盘符进行访问,所以虚拟磁盘上的文件都被自动加密,访问 ...

  10. php面试重要知识点,面试题

    1.什么是引用变量,用什么符号定义引用变量? 概念:用不同的名称引用同一个变量的内容:用&符号定义. 例如: $a = range(0,100); $b = &$a; $b = ran ...