jenkins声明式管道忽略了jenkinsfiles的changelog [英] jenkins declarative pipeline ignoring changelog of jenkinsfiles

查看:222
本文介绍了jenkins声明式管道忽略了jenkinsfiles的changelog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git存储库上有应用程序及其代码.还有用于在其他存储库上构建应用程序的jenkinsfiles和这些文件.问题是詹金斯建立了changelog. Jenkins添加了jenkinsfiles changelog来构建变更集,我不想这么做.因为这些更改是根据与应用程序无关的基础结构进行的.如何预防呢?我没有找到任何解决方法或解决方案.

I have apps and their codes on git repositories. Also jenkinsfiles for building apps and these files on another repository. The problem is jenkins builds changelog. Jenkins add jenkinsfiles changelog to build changesets and I don't want to that. Because these changes are according to infrastructure not relevant with apps. How to prevent this? I didn't find any workaround or solution.

推荐答案

如果我很好,你的问题...我认为您不能从Jenkins从git读取的更改集中删除Jenkinsfile更改,但是,您如果仅对Jenkinsfile进行更改,则可以跳过构建管道.

If I got well your question... I don't think you can remove Jenkinsfile changes from the change set that Jenkins reads from git, but instead, you can skip your pipeline to build if there are only changes on Jenkinsfile.

如果有帮助... 首先,您需要阅读更改集:

If it helps... First place, you need to read the change set:

    def changedFiles = []
    for (changeLogSet in currentBuild.changeSets) { 
        for (entry in changeLogSet.getItems()) { 
            for (file in entry.getAffectedFiles()) {
                changedFiles.add(file.getPath())
            }
        }
    }

然后,您可以检查它是否只是Jenkinsfile:

Then, you can check if it is only Jenkinsfile:

if (changedFiles.size() == 1 && changedFiles[0] == "Jenkinsfile"){
    println "Only Jenkinsfile has changed... Skipping build..."
    currentBuild.getRawBuild().getExecutor().interrupt(Result.SUCCESS) // this skips your build prematurely and makes the rest of the stages green
    sleep(1) // you just need this
}else{
    println "There are other changes rather than only Jenkinsfile, build will proceed."
}

P.S.您有多种方法可以尽早终止作业而不会使构建失败,但这是我的经验,这是最干净的方法,即使您需要允许对Jenkins拥有某些Admin Signatures权限(我之前在另一线程中也看到过这种方法,现在无法找到它)

P.S. You have several ways to terminate the jobs earlier without failing the build, but this one is the cleanest in my experience, even though you need to allow some Admin Signatures Permission on Jenkins (I've seen it in another thread here some time ago, can't find it now though)

这篇关于jenkins声明式管道忽略了jenkinsfiles的changelog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆