Log changes in Jenkins

后端 未结 4 567
天涯浪人
天涯浪人 2021-01-15 12:09

Continuing on my question here: Jenkins pass or fail build on external executable

My build process now builds from source using MS Build, and executes a custom progr

4条回答
  •  一向
    一向 (楼主)
    2021-01-15 12:09

    // This is a deliciously convoluted and fragile hack to force Jenkins to show the
    // changes via a Groovy Postbuild script:
    
    // fake a Subversion changelog.xml file
    changes = new File(manager.build.getRootDir(), "../../workspace/changes.txt")
    changelog = new File(manager.build.getRootDir(), "changelog.xml")
    changelog.withWriter {
      out ->
    out.println(""
      + new java.util.Date() + "")
    message  = ""
    changes.eachLine {
       line ->
         if (line.startsWith("./")) line = line.substring(2)
         if (!".checksums".equals(line)) {
           out.println("" + line + "")
           message += line + "\n"
        }
       }
      out.println("" + message + "")
    }
    
    // get an instance of the SubversionChangeLogParser
    import java.net.URL;
    import java.net.URLClassLoader;
    baseDir = new File(jenkins.model.Jenkins.getInstance().getRootDir(),
      "plugins/subversion/WEB-INF/")
    urls = new URL[2];
    urls[0] = new File(baseDir, "classes/").toURI().toURL() 
    urls[1] = new File(baseDir, "lib/svnkit-1.3.4-hudson-2.jar").toURI().toURL() 
    loader = new URLClassLoader(urls,  manager.getClass().getClassLoader())
    svn = loader.loadClass("hudson.scm.SubversionChangeLogParser").newInstance()
    
    // force the current build to take that parser, parse the changelog.xml,
    // and force it down AbstractBuild's throat, too
    scmField = manager.build.getClass().getSuperclass().getSuperclass().getDeclaredField("scm")
    scmField.setAccessible(true)
    scmField.set(manager.build, svn)
    
    changeSet = svn.parse(manager.build, changelog)
    changeSetField = manager.build.getClass().getSuperclass().getSuperclass().getDeclaredField("changeSet");
    changeSetField.setAccessible(true)
    import java.lang.ref.WeakReference;
    if (changeSetField.getDeclaringClass().isAssignableFrom(WeakReference.class))
      changeSet = new WeakReference(changeSet)
    changeSetField.set(manager.build, changeSet)
    

提交回复
热议问题