Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
720 views
in Technique[技术] by (71.8m points)

svn - Process only changed files

What:
With jenkins I want to process periodically only changed files from SVN and commit the output of the processing back to SVN.

Why:
We are committing binary files into SVN (we are working with Oracle Forms and are committing fmb-Files). I created a script which exports the fmb's to xml (with the original Fmb2XML tool from Oracle) and than I convert the XML to plain source which we also want to commit. This allows us greping, viewing the changes, ....

Problem:
At the moment I am only able to checkout everything, convert the whole directory and committing the whole directory back to SVN. But since all plain text files are newly generated they appear changed in SVN. I want to commit only the changed ones.

Can anyone help me with this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I installed the Groovy plugin, configured the Groovy language and created a script which I execute as "system Groovy script". The scripts looks like:

import java.lang.ProcessBuilder.Redirect

import hudson.model.*
import hudson.util.*
import hudson.scm.*
import hudson.scm.SubversionChangeLogSet.LogEntry

// uncomment one of the following def build = ... lines

// work with current build
def build = Thread.currentThread()?.executable

// for testing, use last build or specific build number
//def item = hudson.model.Hudson.instance.getItem("Update_SRC_Branch") 
//def build = item.getLastBuild()   
//def build = item.getBuildByNumber(35)   

// get ChangesSets with all changed items
def changeSet= build.getChangeSet()
List<LogEntry> items = changeSet.getItems()

def affectedFiles = items.collect { it.paths }

// get filtered file names (only fmb) without path
def fileNames = affectedFiles.flatten().findResults {
    if (it.path.substring(it.path.lastIndexOf(".") + 1) != "fmb") return null
    it.path.substring(it.path.lastIndexOf("/") + 1)
}.sort().unique()

// setup log files
def stdOutFile = "${build.rootDir}\stdout.txt"
def stdErrFile = "${build.rootDir}\stderr.txt"

// now execute the external transforming
fileNames.each {
    def params = [...]
    def processBuilder = new ProcessBuilder(params)

    // redirect stdout and stderr to log files
    processBuilder.redirectOutput(new File(stdOutFile))
    processBuilder.redirectError(new File(stdErrFile))

    def process = processBuilder.start()
    process.waitFor()

    // print log files
    println new File(stdOutFile).readLines()
    System.err.println new File(stdErrFile).readLines()
}

Afterwards I use command line with "svn commit" to commit the updated files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...