1

I wonder if anyone knows how to write a batch script to edit some text in a .cs file. What I want to do is change "AssemblyVersion("1.0.0.0")" "AssemblyVersion("1.0.0.x")" where x++ for every time the job in jenkins is being built. Best Regards Jan

Jan
  • 338
  • 3
  • 18
  • I assume you're running jenkins on windows. I'm not a 100% sure, but I would bet that you can do that with powershell. – Augusto Feb 07 '13 at 07:54
  • There are better tools for this than `cmd`, check out this answer: http://stackoverflow.com/a/3517135/34148 – Anders Lindahl Feb 07 '13 at 07:54
  • The problem is that everything is built on a windows server that acts as a slave to hudson. Hudson on the other hand is a linux server. Just tried to build everything directly on hudson (using the msbuild plugin) and it works fine except for the assemblyfileinfo.cs file which is completely empty. I guess this is because I have to install MSBuildTasks on hudson, and I haven't got a solution for that atm. – Jan Feb 07 '13 at 10:26

2 Answers2

1

Do you want to use only a batch script for this? You could also use Execute Groovy Script option and write some simple groovy script to achieve this

file = new File("folder/path/myfile.cs")
fileText = file.text;
fileText = fileText.replaceAll(srcExp, replaceText);
file.write(fileText);

You can also use the availabe environment variables from your jenkins job to construct your replace text. These variables will be present at /env-vars.html

Shiva Kumar
  • 3,111
  • 1
  • 26
  • 34
  • how can I iterate over jenkins varaibles to replace each of them with its value in the file? – Dejell Nov 19 '14 at 12:37
0

Stay away from "batch-file automation" - will only cause you grief.
(for a starter, different versions of Windows support a different set of batch-commands)

You should incorporate the build-number in the script as an Environment Variable -
use either the "built-in" %BUILD_NUMBER% parameter or set your own format with
the Formatted Version-Number Plugin .

If you do need to edit that 'CS' file, I suggest using either Perl or PowerShell.

Cheers

Gonen
  • 4,005
  • 1
  • 31
  • 39