犯傻的水桶 · CorrelationIdConverter ...· 2 月前 · |
爱搭讪的蚂蚁 · centos7.6编写自己的启动服务,运行s ...· 9 月前 · |
朝气蓬勃的沙发 · plotly入门(vue项目中)_vue-p ...· 1 年前 · |
鼻子大的苹果 · 大模型-FastChat-Vicuna(小羊 ...· 1 年前 · |
坚韧的萝卜 · python修改json文件中的value-掘金· 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)
坚韧的萝卜 · python修改json文件中的value-掘金 1 年前 |