jenkins持续集成go应用
上文讲到使用supervisor管理我们的终端应用,这次讲一下使用jenkins持续集成
下面分别讲一下pipeline里每一个段落的含义
agent any 使用任意节点构建
parameters 模块使用参数化构建
environment 脚本全局变量
options 脚本定义参数,超时时间等
stage 每个步骤
checkout 拉取代码命令
when 当全局变量environment的value期待值符合的时候执行steps
post 结束后执行,always代表无论项目是否执行成功都要执行模块里的内容。常用的还有changed,failure,success,unstable
其他地方大多数使用了ansible和shell命令,比如ansible ${ip} -m shell -a "supervisorctl restart beepkg" 是使用ansible的shell 调用$ip的supervisorctl 重启beepkg队列
def createVersion() {
// 定义一个版本号作为当次构建的版本,输出结果 20191210175842_69
return new Date().format('yyyyMMddHHmmss') + "_${env.BUILD_ID}"
}
pipeline{
agent any
parameters {
gitParameter branch: '', branchFilter: '.*', defaultValue: 'master', description: '选择代码分支', name: 'branch', quickFilterEnabled: false, selectedValue: 'NONE', sortMode: 'NONE', tagFilter: '*', type: 'PT_BRANCH'
choice choices: ['吴增辉'], description: '填写开发人员', name: 'developer'
choice choices: ['yes','no'], description: '是否备份', name: 'backup'
text defaultValue: '', description: '请填写更新日志', name: 'record'
}
environment {
def ip = "172.16.0.62_go2noticeposp"
def remotedir = "/data/beego/cups-api"
def _version = createVersion()
def tmpdir = "/tmp/cups-api_${_version}"
}
options {
disableConcurrentBuilds()
timeout(time: 3, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '10'))
}
stages{
stage('拉取代码'){
steps{
deleteDir()
checkout([$class: 'GitSCM', branches: [[name: '$branch']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '9df82ae3-5563-4d32-808b-00e8aa9ae26c', url: 'git@192.168.80.13:wuzh/cups-api.git']]])
}
}
stage('打包应用'){
options {
timeout(time: 4, unit: 'MINUTES')
}
steps{
sh label: '', script: '/root/go/bin/bee pack'
}
}
stage('备份服务器文件'){
when {
environment name: 'backup',
value: 'yes'
}
steps{
sh label: '', script: '''ansible ${ip} -m file -a "path=$tmpdir state=directory"
ansible ${ip} -m shell -a "rsync -qa $remotedir/* $tmpdir --exclude=\'logs\'"'''
}
}
stage('发布文件到服务器'){
steps{
sh label: '', script: 'tar -zxf ${WORKSPACE}/go_online-cups-api.tar.gz'
sh label: '', script: 'ansible ${ip} -m synchronize -a "src=${WORKSPACE}/go_online-cups-api dest=$remotedir delete=no archive=yes compress=yes rsync_opts=--exclude=\'conf\'"'
}
}
stage('重启supervisor队列'){
steps{
sh label: '', script: 'ansible ${ip} -m shell -a "supervisorctl restart beepkg"'
sh label: '', script: 'ansible ${ip} -m shell -a "supervisorctl status beepkg"'
}
}
stage('生成日志'){
steps{
sh label: '', script: '''today=`date "+%Y_%m_%d"`
now=`date "+%Y_%m_%d_%H_%M_%S"`
echo "时间: $now" >> /root/update_log/$today
echo "开发者: $developer" >> /root/update_log/$today
echo "git地址: git@192.168.80.13:wuzh/cups-api.git" >> /root/update_log/$today
echo "分支名字: $branch" >> /root/update_log/$today
echo "更新日志: $record" >> /root/update_log/$today
echo -e \'-----------------------------------\\n\' >> /root/update_log/$today'''
}
}
}
post('send mail'){
always{
emailext(
subject: '构建通知:${PROJECT_NAME} - Build # ${BUILD_NUMBER} -${BUILD_STATUS}!',
body: '${FILE,path="/root/script/email.html"}',
to: 'guoyabin@96199.com.cn')
}
}
}
执行效果如下:

jenkins持续集成go应用的更多相关文章
- python_java_selenium_ jenkins持续集成Firfox_chrome浏览器不显示的解决方法?
python_java_selenium_ jenkins持续集成Firfox_chrome浏览器不显示的解决方法: 原因:因为jenkins是用windows installer 安装成 windo ...
- jenkins持续集成源码管理选项为None,构建失败找不到git.exe解决办法
我的jenkins版本为Jenkins ver. 2.19.1 1.源码管理选项只有None的解决办法: 在插件管理中心,搜索对应的源码管理插件这里以git为例,搜索git plugin点击右下角的安 ...
- 【转】jenkins持续集成配置
搭建jenkins持续集成服务器 1.jenkins简介 Jenkins,前身为Hudson,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,包括: 持续的软件版本发布/测试项目. 监控 ...
- Jenkins持续集成
Jenkins持续集成 & .NET 最近受累于测试环境每次发布都很麻烦,而且我们有多个测试环境,因此专门抽时间做了Jenkins的配置和研究. 折腾了两天终于绿灯以后,先来个截图,Blu ...
- Jenkins持续集成相关文章整理
构建iOS持续集成平台(一)——自动化构建和依赖管理 构建iOS持续集成平台(二)——测试框架 构建iOS持续集成平台(三)——CI服务器与自动化部署 使用Jenkins搭建iOS开发的CI服务器 一 ...
- Docker+Jenkins持续集成环境(4):使用etcd+confd实现容器服务注册与发现
前面我们已经通过jenkins+docker搭建了基本的持续集成环境,实现了服务的自动构建和部署,但是,我们遇到一个问题,jenkins构建出来的镜像部署后,需要通过ip:port去访问,有什么更好的 ...
- Docker+Jenkins持续集成环境(5): android构建与apk发布
项目组除了常规的java项目,还有不少android项目,如何使用jenkins来实现自动构建呢?本文会介绍安卓项目通过jenkins构建的方法,并设计开发一个类似蒲公英的app托管平台. andro ...
- windows部署jenkins持续集成maven测试项目不能访问测试报告
买了一台阿里云的服务器用于练习maven test项目,系统版本wiondows server 2012,将jenkins war包部署在Tomcat服务器上,项目构建后,生成的报告在C:\Windo ...
- Linux-GitLab+Jenkins持续集成+自动化部署
GitLab+Jenkins持续集成+自动化部署 什么是持续集成? (1)Continuous integration (CI) 持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个 ...
- 行为驱动:Cucumber + Selenium + Java(二) - extentreports 测试报告+jenkins持续集成
1.extentreports 测试报告 pom文件 <dependency> <groupId>com.vimalselvam</groupId> <art ...
随机推荐
- 51 Nod 1083 矩阵取数问题(动态规划)
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1083 题目分析:通过读题发现我们只能往右边或者下边走,意味着 ...
- 一文看懂B端产品和C端产品
大纲 什么是B端产品 什么是C端产品 为什么会产生B端产品和C端产品 怎么判断一个产品是B端还是C端 B端产品和C端产品存在哪些差异 C端产品经理如何向B端产品经理转型 写在最后 什么是B, Bu ...
- Android官方文档翻译 九 2.2Adding Action Buttons
Adding Action Buttons 增加动作按钮 This lesson teaches you to 这节课教给你 Specify the Actions in XML 在XML中指定动作 ...
- 《剑指offer》面试题61. 扑克牌中的顺子
问题描述 从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连续的.2-10为数字本身,A为1,J为11,Q为12,K为13,而大.小王为 0 ,可以看成任意数字.A 不能视为 14. 示例 ...
- 【算法】KMP
@ 目录 一. 暴力匹配 二.KMP的基本思想 三.next[]的求法 1. 暴力求解 2. 递推求解 四.KMP算法 一. 暴力匹配 字符串匹配的最直接的方法就是暴力匹配,而KMP算法也是基于暴力算 ...
- 【刷题-PAT】A1111 Online Map (30 分)
1111 Online Map (30 分) Input our current position and a destination, an online map can recommend sev ...
- vue学习2-bind属性绑定
需要加上 v-html才能显示网页
- 多线程创建的方式一(继承Thread类)
1 package multithread; 2 3 /* 4 * 如何创建一个线程呢? 5 * 6 * 创建线程方式一:继承Thread类. 7 * 8 * 步骤: 9 * 1,定义一个类继承Thr ...
- Allure测试报告完整学习笔记
目录 简介 安装Allure Allure测试报告的结构 Java TestNG集成Allure Report Python Pytest集成Allure Report 简介 假如你想让测试报告变得漂 ...
- web下载文件的头消息
resp.setHeader("Content-disposition","attachment;filename="+filename);