Commit file from Jenkins workspace to SVN

为君一笑 提交于 2019-11-30 16:51:48

问题


I have a saved project in Subversion repository and compiles it with Jenkins. When I run the build, Jenkins pulls project into workspace directory. I need commit one changed file from Jenkins workspace into Subversion. How can I do it??

Thanks for answers...


回答1:


Can you give a few more details? Exactly what is this file, and why does it need to be committed as part of your Jenkins build? What are you building (Java? C++? .NET?) and how are you building it?

Normally, you shouldn't put anything under version control except source files. That is, if you can build it, you shouldn't put it into version control. A lot of people like to commit their built code into their version control system, but this is usually a big mistake. binary files are much bigger and rarely diff. This results in a source repository that's 90% compiled code -- almost all of it obsolete. This is especially problematic with Subversion which doesn't have a way to (easily) remove obsolete code.

Jenkins has a feature that allows you to archive your built files for easy access. We use this all the time. We build our code, and the program is available in Jenkins for downloads. Even better, Jenkins will delete older builds (you can save the last X builds or save only builds younger than X days). And if you have a release candidate build, you can lock that build to prevent it from being deleted.


Still, if you insist on doing this, there are several things you can do and things you have to watch out for:

  1. When you have Jenkins setup to automatically build each change, and you commit a change in your version control system, Jenkins will see that, and start a new build. Then, Jenkins saves the change, sees the change, and does another build. Make sure you exclude the files or directories from Jenkins' consideration when it should do a build. You can specify this when you specify the URL of the checkout.

  2. Unlike most version control systems, Subversion was made to be client independent. There's an actual API for clients. The standard Subversion command line client isn't needed in Jenkins, so make sure it's installed. Make sure you install a client compatible with the Jenkins built in SVNKit client. This is especially true since Subversion 1.6, 1.7, and 1.8 all take a different client format.

  3. You can add multiple build steps to your build in Jenkins. Just add a new shell script or batch script step, and add in a svn commit -m "comment of some sort" step. It's pretty simple to do once you've taken care of the first two points. However, please think carefully why you're doing this.

As I said before, 99.9999% of the time, you shouldn't be using Jenkins to commit changes it built. I'm sure that 0.0001% reason exists somewhere, but I've never seen it. If you want to make built files universally accessible to your other projects, use Jenkin's ability to archive built files.

If a product Jenkins is building is needed for another build, you can use the Copy Artifact Plugin to copy a build artifact to another job, and then fire off that job. Even better, use a release repository system. In Java, you can use a Maven release repository like Nexus or Artifactory. To use and deploy artifacts to that repository, you can use Ivy or Maven or Gradle. If you are building .NET, look at Nuget.




回答2:


Please have a look to this answer: Jenkins svn commit post-build

It should be possible to commit with a new build step (or a post build step).

But be careful with the SVN layout of the Jenkins workspace. The subversion plugin is using the SVNKit to deal with the SVN commands. Your workspace maybe use the SVN layout 1.6.

If the SVN client is more recent on your machine, your SVN commit will fail with the following error: org.apache.subversion.javahl.ClientException: The working copy needs to be upgraded svn: Working copy 'C:.... is too old (format 10, created by Subversion 1.6)




回答3:


You could carefully use:

svn commit -username someuser -password %injected_password% 

to inject password in Build Environment, this command injects passwords to the build as environment variables

Watch out: that password might be visible in the job trigger batch.



来源:https://stackoverflow.com/questions/28105070/commit-file-from-jenkins-workspace-to-svn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!