jenkins2 pipeline实例
实例 Pipeline
2023-09-27 14:19:39 时间
比较完整的实例,使用了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}" } }
相关文章
- Java 线程实例二(终止线程、生产者/消费者问题、获取线程状态、获取所有线程、查看线程优先级、中断线程)
- TCP/IP协议族——IP工作原理及实例具体解释(上)
- zeromq简介及各个通讯模式实例详解(附java实现)
- C#-深入解析编程中泛型委托的使用及多播委托实例
- CvMat、Mat、IplImage之间的转换详解及实例
- C语言中的弱符号(weak)用法及实例
- python中super的用法实例解析
- 《HTML5 开发实例大全》——1.29 编辑修改网页中的文字
- Hive(九)Hive 执行过程实例分析
- Android Touch系统简介(二):实例详解onInterceptTouchEvent与onTouchEvent的调用过程
- Linux多线程实例练习 - pthread_cancel()
- 在控制台拿到vue的实例
- 使用Axis2方式发布webService实例说明
- hadoop-Mapreduce实例WordCoun
- 图像处理中的数学原理具体解释21——PCA实例与图像编码
- MyBatis的架构设计以及实例分析--转
- Java元组Tuple使用实例--转载
- 【数据库学习】——从零学习SQL语句(含SQL数据类型、SQL语句实例操作)