满身肌肉的大脸猫 · 解决jenkins发版报错:JAR ...· 1 周前 · |
玉树临风的领带 · IDEA 使用系列之 Alibaba ...· 1 周前 · |
直爽的长颈鹿 · EAGAIN、EWOULDBLOCK、EIN ...· 7 月前 · |
八块腹肌的机器猫 · 正则表达式 – 示例 | 菜鸟教程· 1 年前 · |
星星上的斑马 · python - pipenv ...· 1 年前 · |
深沉的鸡蛋面 · python ...· 1 年前 · |
谁有一个Jenkins Pipeline脚本,可以将自上次成功构建以来的所有更改填充到一个变量中?我正在使用git和一个多分支管道作业。
有一个 Changes Since Last Success Plugin 可以帮你做到这一点。
我设法拼凑了一些东西。我非常确定,你可以更好地迭代数组,但这是我现在得到的:
node('Android') {
passedBuilds = []
lastSuccessfulBuild(passedBuilds, currentBuild);
def changeLog = getChangeLog(passedBuilds)
echo "changeLog ${changeLog}"
def lastSuccessfulBuild(passedBuilds, build) {
if ((build != null) && (build.result != 'SUCCESS')) {
passedBuilds.add(build)
lastSuccessfulBuild(passedBuilds, build.getPreviousBuild())
@NonCPS
def getChangeLog(passedBuilds) {
def log = ""
for (int x = 0; x < passedBuilds.size(); x++) {
def currentBuild = passedBuilds[x];
def changeLogSets = currentBuild.rawBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
log += "* ${entry.msg} by ${entry.author} \n"
return log;
}
根据CaptRespect的回答,我想出了以下脚本用于声明性管道:
def changes = "Changes:\n"
build = currentBuild
while(build != null && build.result != 'SUCCESS') {
changes += "In ${build.id}:\n"
for (changeLog in build.changeSets) {
for(entry in changeLog.items) {
for(file in entry.affectedFiles) {
changes += "* ${file.path}\n"
build = build.previousBuild
echo changes
在
stage->when->expression
部件中,只有在某些文件发生更改时才运行阶段,这一点非常有用。不过,我还没有讲到这一部分,我很乐意从这个库中创建一个共享库,并向它传递一些要检查的全局模式。
编辑:
Check the docs
btw,如果你想更深入一点的话。您应该能够仅将所有
object.getSomeProperty()
调用转换为
entry.someProperty
。
对于任何使用Accurev的人来说,这里是andsens答案的改编。andsens的答案不能使用,因为Accurev插件没有实现getAffectedFiles。可以在 here. 中找到扩展ChangeLogSet.Entry类的AccurevTransaction的文档
import hudson.plugins.accurev.*
def changes = "Changes: \n"
build = currentBuild
// Go through the previous builds and get changes until the
// last successful build is found.
while (build != null && build.result != 'SUCCESS') {
changes += "Build ${build.id}:\n"
for (changeLog in build.changeSets) {
for (AccurevTransaction entry in changeLog.items) {
changes += "\n Issue: " + entry.getIssueNum()
changes += "\n Change Type: " + entry.getAction()
changes += "\n Change Message: " + entry.getMsg()
changes += "\n Author: " + entry.getAuthor()
changes += "\n Date: " + entry.getDate()
changes += "\n Files: "
for (path in entry.getAffectedPaths()) {
changes += "\n " + path;
changes += "\n"
build = build.previousBuild
echo changes
writeFile file: "changeLog.txt", text: changes
为了以字符串列表的形式返回更改,而不仅仅是打印它们,您可以使用此函数(基于@andsens答案):
def getChangesSinceLastSuccessfulBuild() {
def changes = []
def build = currentBuild
while (build != null && build.result != 'SUCCESS') {
changes += (build.changeSets.collect { changeSet ->
(changeSet.items.collect { item ->
(item.affectedFiles.collect { affectedFile ->
affectedFile.path
}).flatten()
}).flatten()
}).flatten()
build = build.previousBuild
return changes.unique()
}
这是我使用的:
def listFilesForBuild(build) {
def files = []
currentBuild.changeSets.each {
it.items.each {
it.affectedFiles.each {
files << it.path
files
def filesSinceLastPass() {
def files = []
def build = currentBuild
while(build.result != 'SUCCESS') {
files += listFilesForBuild(build)
八块腹肌的机器猫 · 正则表达式 – 示例 | 菜鸟教程 1 年前 |