Question

How do I commit a single file to an SVN 1.7 repository using Gradle?

I'd like to use Jenkins to provide the credentials, the commit message, and the path to the file.

Était-ce utile?

La solution

Drawing from this answer, this is the Gradle task that commits a single file using SVNKit.

buildscript {
    repositories { mavenCentral() }
    dependencies { classpath "org.tmatesoft.svnkit:svnkit:1.7.11"}
}

import org.tmatesoft.svn.core.wc2.*
import org.tmatesoft.svn.core.wc.*
import org.tmatesoft.svn.core.*

task svnCommitFile(){
    description = "Commits a single file to an SVN repository"
    doLast{
        if (!project.hasProperty("commitMsg")){
          ext.commitMsg = "None"
        }
        SvnOperationFactory svnOperationFactory = new SvnOperationFactory()
        def authentication = SVNWCUtil.createDefaultAuthenticationManager(svnUser, svnPassword)
        svnOperationFactory.setAuthenticationManager(authentication)
        try {
            SvnCommit commit = svnOperationFactory.createCommit()
            commit.setSingleTarget(SvnTarget.fromFile(new File(fileToCommit)))
            commit.setCommitMessage(commitMsg)
            SVNCommitInfo commitInfo = commit.run()
            println "Commit info: " + commitInfo
            println "Commit message: " + commitMsg
        } finally{
            svnOperationFactory.dispose()
        }
    }
}

Call it with gradle svnCommitFile -PfileToCommit="path/to/file" -PcommitMsg="My message" -PsvnUser="me" -PsvnPassword="verySecret"


If this commit is done with Jenkins after every commit to the project, you will get in an infinite build loop, because a commit causes a build which causes a commit which causes a build...

Therefore Jenkins should ignore its own commits: In your project's build configuration go to Source Code Management --> Subversion --> Advanced and add jenkins (or however you call your automated committer) to the Excluded Users.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top