Write a batch script to edit text in a .cs file
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(“22.214.171.124″)” “AssemblyVersion(“1.0.0.x”)” where x++ for every time the job in jenkins is being built.
Best Regards Jan
2 Solutions collect form web for “Write a batch script to edit text in a .cs file”
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
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.