Can I Use The SVNKit Command Line To Merge Before Building

Answered

I previously had a single server with agents on that server so to merge before building I would save a script on the server and call that from the command line runner.

https://teamcity-support.jetbrains.com/hc/en-us/community/posts/206181009-Run-Shell-Script-Before-Build-For-SVN-Auto-Merge

Unsurprisingly, this turned out to not scale.

Not only did I run into the issue of the file not existing on new servers, but I also ran into the use cases of svn either not being installed or an older version being installed than the version being used by TeamCity to check out the code.

Is it possible to use svnkit (shipped with TeamCity) in a command line runner to merge a few branches before a build?

I need to do

  • svn revert
  • svn stat
  • svn log
  • svn merge

 

0
3 comments
Avatar
Permanently deleted user

Hello!

You can use SVNKit as a Java library to run svn commands you need as the first step using Command Line or Ant Build Runner.

E.g.

set CLASSPATH=%teamcity.agent.home.dir%\plugins\svnAgent\lib\*;.\
"%env.TEAMCITY_JRE%\bin\java" org.tmatesoft.svn.cli.SVN log --username <username> --password <password>

Please refer to https://svn.svnkit.com/repos/svnkit/tags/1.3.1-rc1/www/kb/user-guide-command-line-client.html and https://svn.svnkit.com/repos/svnkit/branches/ssh.ping/www/kb/ant.html for more info about SVNKit.

Please also refer to the List of VCS Checkout Modes to enable Always checkout files on agent mode to have .svn folder on agent.

You can also use Administration | Tools | Install Tool... | Zip Archive to distribute a proper svn client onto your agents.

0

Thanks. I have done something like that now.

I wanted to use some bash commands to parse the output though so I needed the command line runner to be shell and not Windows batch.

I now have 2 command line runners, one to create the shell script and one to run it using bash (all our servers have git bash installed).

copy %%0 %teamcity.agent.home.dir%
@echo off
setlocal
del %teamcity.agent.home.dir%\auto-merge.sh
>>%teamcity.agent.home.dir%\auto-merge.sh echo #!/bin/bash
>>%teamcity.agent.home.dir%\auto-merge.sh echo #
>>%teamcity.agent.home.dir%\auto-merge.sh echo echo 'jdk.certpath.disabledAlgorithms=MD2, RSA keySize ^< 1024' ^> security.properties
>>%teamcity.agent.home.dir%\auto-merge.sh echo echo 'jdk.tls.disabledAlgorithms=SSLv3, RC4, DH keySize ^< 768' ^>^> security.properties
>>%teamcity.agent.home.dir%\auto-merge.sh echo agent_dir=$(cygpath '%teamcity.agent.home.dir%')
>>%teamcity.agent.home.dir%\auto-merge.sh echo svnkit_lib=${agent_dir}/plugins/svnAgent/lib
>>%teamcity.agent.home.dir%\auto-merge.sh echo export JAVA_HOME=${agent_dir}/jre
>>%teamcity.agent.home.dir%\auto-merge.sh echo CLASSPATH=^"${svnkit_lib}/svnkit-cli-1.8.12.jar:${svnkit_lib}/svnkit-1.8.12.jar:${svnkit_lib}/sequence-library-1.0.3.jar:${svnkit_lib}/sqljet-1.1.10.jar:${svnkit_lib}/antlr-runtime-3.4.jar:${svnkit_lib}/jna-4.1.0.jar:${svnkit_lib}/jna-platform-4.1.0.jar^"
>>%teamcity.agent.home.dir%\auto-merge.sh echo svnkit=^"${JAVA_HOME}/bin/java -Djava.security.properties=${agent_dir}/security.properties -cp ${CLASSPATH} org.tmatesoft.svn.cli.SVN --trust-server-cert --non-interactive --username=%vcsroot.user% --password=myplaintextpassword^"
>>%teamcity.agent.home.dir%\auto-merge.sh echo cd $(cygpath '%teamcity.build.checkoutDir%')
>>%teamcity.agent.home.dir%\auto-merge.sh echo #
>>%teamcity.agent.home.dir%\auto-merge.sh echo branches=https://my.svn.server/repo/branches
>>%teamcity.agent.home.dir%\auto-merge.sh echo while :
>>%teamcity.agent.home.dir%\auto-merge.sh echo do
>>%teamcity.agent.home.dir%\auto-merge.sh echo     ${svnkit} merge $branches/$1 .
>>%teamcity.agent.home.dir%\auto-merge.sh echo     shift 1;
>>%teamcity.agent.home.dir%\auto-merge.sh echo     if [[ $1 == '' ]]; then
>>%teamcity.agent.home.dir%\auto-merge.sh echo        break;
>>%teamcity.agent.home.dir%\auto-merge.sh echo     fi
>>%teamcity.agent.home.dir%\auto-merge.sh echo done
>>%teamcity.agent.home.dir%\auto-merge.sh echo cd -
>>%teamcity.agent.home.dir%\auto-merge.sh echo rm security.properties

Could I use the Install Tools to install this script instead of creating it with the command line runner like this?

 

0
Avatar
Permanently deleted user

Yes, you may propagate your script on Agents using Administration | Tools | Install Tool... | Zip Archive.

It will be placed into <Agent home>/tools/ directory.

You can find more information about it here and here.

0

Please sign in to leave a comment.