jenkins2 pipeline实例
比较完整的实例,使用了maven打包,git tag,发通知邮件,等待用户deploy,deploy到nexus。
文章来自:http://www.ciandcd.com
文中的代码来自可以从github下载: https://github.com/ciandcd
源代码和文章来自: https://grensesnittet.computas.com/pipeline-as-code-continuous-delivery-with-jenkins-2-0/
代码如下:
// Run this on the master node:
node {
// The JDK is configured as a tool with the name 'jdk-8u77' in the Jenkins 'Global Tool Configuration'
env.JAVA_HOME="${tool 'jdk-8u77'}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}" // Maven is configured as a tool with the name 'M3' in the Jenkins 'Global Tool Configuration'.
def mvnHome = tool 'M3' stage 'Checkout'
// Configure the credential in Jenkins, and use the credential's ID in the following step:
git url: 'ssh://git@gitrepo.computas.com/fs/fs-knowledge-editor.git', credentialsId: '8dbfb6d2-2549-4c6e-9a6e-994ae8797efc' stage 'Build and tag'
// Define the version of this build.
// BASE_VERSION is defined as a build parameter in the UI definition of the job.
// Note how Groovy code is used to format the number of the current build.
def version = "${BASE_VERSION}-J2TEST-" + currentBuild.number.toString().padLeft(4,'0')
// Execute the maven command as a shell command step. On Windows, a 'bat'-step would be used instead.
sh "${mvnHome}/bin/mvn clean verify -f KnowledgeEditor/pom.xml -Dfs.version=${version}"
// Archive the zip file for access in through the Jenkins UI, or for other uses.
archive 'KnowledgeEditor/com.computas.fs.ke.products/target/products/*.zip' // Each build is tagged with an annotated tag.
// There is no pipeline plugin for this (the Git Publisher plugin is not compatible),
// so everything has to be implemented using shell commands.
// First, we have to configure git with the mandatory user information:
sh "git config user.name \"Jenkins Pipeline\""
sh "git config user.email bob@computas.com"
// Next, tag this commit.
def msg = "\"Automatically created tag ${version}\""
sh "git tag -a -m ${msg} ${version}"
// Finally, push to the repo.
// For this to work, the ssh keys must be available in Jenkins' ~/.ssh folder
sh "git push origin ${version}" // Send a mail to the person responsible for manual testing and release.
mail subject: 'A new version of KEIII is available for testing.',
body: 'A new version of KEIII is available for testing and approval of release.',
charset: 'utf-8',
from: 'bob@computas.com',
mimeType: 'text/plain',
to: 'fs-tester@computas.com' stage 'Release'
// User input showing up in the Jenkins UI.
// If the timeout is reached, an exception is thrown and the build aborted.
timeout(time: 120, unit: 'SECONDS') {
input message: 'Do you want to release this version, ' + version + ', of KEIII?', ok: 'Release'
}
// A catch block could deal with the exception. // In order to release to Nexus, deploy and access information needs to be made available in
// a maven settings file. This configuration is copied into the file defined as
// mavenSettingsFile from the corresponding managed file in Jenkins...
def mavenSettingsFile = "${pwd()}/.m2/settings.xml" // ... using the configuration file build wrapper:
wrap([$class: 'ConfigFileBuildWrapper',
managedFiles: [
[fileId: '85adba0c-908b-4dbf-b3aa-65fe823e8984',
targetLocation: "${mavenSettingsFile}"]]]) {
// deploy to Nexus
sh "${mvnHome}/bin/mvn deploy -s ${mavenSettingsFile} -f KnowledgeEditor/pom-deploy.xml -Dfs.version=${version}"
}
}
jenkins2 pipeline实例的更多相关文章
- jenkins2 pipeline 语法快速参考
jenkins2 pipeline中常用的语法快速参考. 文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://github.com/ciand ...
- jenkins2 pipeline高级
jenkins2 pipeline里groovy的高级用法.翻译自:https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL. ...
- jenkins2 pipeline入门
本文通过简单的pipeline的实例和详细的讲解,能够学习基本pipeline的groovy用法,然后开始实现自己的pipeline job. 翻译和修改自:https://github.com/je ...
- jenkins2 pipeline介绍
文章来自:http://www.ciandcd.com 文中的代码来自可以从github下载: https://github.com/ciandcd 什么是jenkins2的pipeline? ...
- jenkins2 -pipeline 常用groovy脚本
jenkins2的核心是pipeline,pipeline的核心是groovy. 那有一些基础的groovy是必须经常使用的,如变量赋值,变量引用,打印变量,输出字符,任务调用,循环判断等. Groo ...
- jenkins2 pipeline插件的10个最佳实践
jenkins pipeline的10个最佳实践. 文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://github.com/ciandcd ...
- item pipeline 实例:爬取360摄像图片
生成项目 scrapy startproject image360 cd Image360 && scrapy genspider images images.so.com 一. 构 ...
- Jenkins pipeline 入门到精通系列文章
Jenkins2 入门到精通系列文章. Jenkins2 下载与启动jenkins2 插件安装jenkins2 hellopipelinejenkins2 pipeline介绍jenkins2 jav ...
- Jenkins2 插件 Pipeline+BlueOcean 实现持续交付的初次演练
需要完成的目标 使用Pipeline完成项目的checkout,package.deploy.restart 提取出公有部分封装为公有JOB 实现pipeline对其他JOB的调用和逻辑的判断 实现任 ...
随机推荐
- VC++ 中简单操作MP3音乐的方法,小结
#include <windows.h> #include <stdio.h> #include <mmsystem.h> #include <shellap ...
- 先进先出集合queue
先进先出集合queue Enqueue添加到集合最后 Dequeue移除集合第一个对象并返回
- 基于WebView的混合编程
近日公司需求变更,以前一个页面是后台返回HTML字段,然后我们直接用webView接收,现在新增一个页面,数据后台返回非HTML,页面跟前面一直,所幸自己会点HTML,所以偷了个懒,自己用代码把数据组 ...
- Centos上DNS服务器的简单搭建
1:安装软件包 yum -y install bind bind-chroot bind-utils bind-libs 2:修改配置文件 1): vim /etc/named.conf 2):在主 ...
- java文件乱码
要让一个 Java 源文件打开时编码格式为 UTF-8,需要做2件事情:1)设置Java 源文件的默认编码格式为UTF-8:2)设置workspace的编码格式为UTF-8. 相应设置如下: 设置 J ...
- Selenium2+python自动化17-JS处理滚动条
前言 selenium并不是万能的,有时候页面上操作无法实现的,这时候就需要借助JS来完成了. 常见场景: 当页面上的元素超过一屏后,想操作屏幕下方的元素,是不能直接定位到,会报元素不可见的. 这时候 ...
- Visual Studio 必备神器
会使用工具是人类文明的一大进步,今天敏捷大行其道,好的工具可以大大的提高生产力,这里说的工具都是VS平台上的扩展工具,一些机械的部分可以交给工具去处理,自己多关注其他部分.下面分享下我觉得不错的工具, ...
- [题解]某模拟题(USACO月赛部分题+noip2005部分题)
题目描述 农场上有N(1 <= N <= 50,000)堆草,放在不同的地点上.FJ有一辆拖拉机,也在农场上.拖拉机和草堆都表示为二维平面上的整数坐标,坐标值在1..1000的范围内.拖拉 ...
- VS2013使用rtklib中需要注意的一些问题(编译)
最近因为项目需要需要对rtcm数据进行解码,rtklib提供了很多底层的函数,准备直接输出标准DLL的方式供C#调用.下面把项目中引用rtklib源码需要注意的地方记录下. 1. 首先在vs2013中 ...
- java中final,finally和finalize的区别
final,finally和finalize的区别: final:最终的意思,可以修饰类,成员变量,成员方法 修饰类,类不能被继承 修饰变量,变量是常量 修饰方法,方法不能被重写 finally:是异 ...