栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

自上次成功构建以来,如何使用Groovy获取有关Jenkins的提交信息?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

自上次成功构建以来,如何使用Groovy获取有关Jenkins的提交信息?

在gradle / maven步骤之后->执行系统常规脚本,添加新的构建步骤。

适应性代码:

import com.tikal.jenkins.plugins.multijob.*import hudson.*import hudson.model.*import hudson.plugins.git.*import hudson.slaves.*import hudson.tasks.*def ln = System.getProperty('line.separator')println "---------------Groovy Changelog script Started---------------$ln"def lastSuccesfulBuild = build.previousNotFailedBuilddef failed = build.result != hudson.model.Result.SUCCESSprintln "Last Succesful Build: ${lastSuccesfulBuild}"println "Current Build Result, is failed?: ${failed}"def currResult = build.resultdef prevResult = build.previousBuild?.result ?: nulldef consecutiveSuccess = currResult == hudson.model.Result.SUCCESS && prevResult == hudson.model.Result.SUCCESSdef builds = []def changes = []def count = 0if (consecutiveSuccess) {    println "Last Build was sucessful, getting latest changes$ln"    builds << build    def changeItems = build.changeSet.items    println "Change Items: ${changeItems}$ln"    count += changeItems.length    changes += changeItems as List} else {    println "Last Build was not sucessful, getting changes from all failed build as well$ln"    println "BUILD: $build$ln"    println "Hudson version: $build.hudsonVersion$ln"    println "Change set: $build.changeSet$ln"    println "Change set items: $build.changeSet.items$ln"    while (lastSuccesfulBuild) {        builds << lastSuccesfulBuild        def changeSet = lastSuccesfulBuild.changeSet        if (!changeSet.emptySet) { def changeItems = lastSuccesfulBuild.changeSet.items count += changeItems.length changes += changeItems as List        }        lastSuccesfulBuild = lastSuccesfulBuild.nextBuild    }}def file = new File(build.getEnvVars()["WORKSPACE"] + '\changelog')file.delete()file = new File(build.getEnvVars()["WORKSPACE"] + '\changelog')if (count ==0){    file << "No changes.$ln"}changes.each { item ->    println "item: $item$ln"    println "author: $item.authorName$ln"    println "msg: $item.msg$ln"    println "id: $item.id$ln"    println "revision: $item.revision$ln"    println "comment: $item.comment$ln"    println "commentAnnotated: $item.commentAnnotated$ln"    println "affectedFiles: $item.affectedFiles$ln"    println "affectedPaths: $item.affectedPaths$ln"    println "commitId: $item.commitId$ln"    println "timestamp: $item.timestamp$ln"    println "date: $item.date$ln"    file << "Commit ID: $item.id, by $item.author on $item.date, timestamp: $item.timestamp$ln"    file << "$item.comment$ln"    item.affectedFiles.each { cl ->         println "editType: $cl.editType.description$ln"        println "changeSet: $cl.changeSet$ln"        println "path: $cl.path$ln"        println "src: $cl.src$ln"        println "dst: $cl.dst$ln"        file << "$cl.editType.description: $cl.path$ln"    }    file << "$ln"}println "---------------Groovy Changelog script Finished---------------$ln"


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/401612.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号