I\'m currently using the Jenkins \"Version Number Plug-In\" to set an Environment Variable for build version. This works fine within jenkins but i need a way to pass this to MSB
The easiest way I´ve found to do this is using the Change Assembly Version. Using that plugin you only need to provide the version number (or the environment variable used) and it will replace it in all the AssemblyInfo.cs files in your workspace.
A very quick work around to this is to create a powershell task before your msbuild task. This is assuming you defined VERSION variable as above (without the %%). And you checked delete workspace before build starts.
This is the code for the powershell task.
gci -rec -Filter *AssemblyInfo* | ForEach { (Get-Content $_.FullName) | ForEach-Object {$_ -replace "1.0.0.0",$env:VERSION } | Set-Content $_.FullName}
Environment Variable Name should be written without the percent-marks ('%'), like this:
VERSION
apart from that, I think you are good to go.
May also consider changing
${BUILDS_ALL_TIME}
to
${BUILDS_ALL_TIME, XX}
(this will enforce a two-digit build-number with leading zeros)
This is a MSBuild target that replaces the revision number in the file GlobalAssemblyInfo.cs with the SVN_REVISION variable from Jenkins.
We have a multi project solution where each project references the same GlobalAssemblyInfo for common information (like version). Modify this so it fits your setup.
By having the Exists condition the target executes on developer machines where the MSBuildCommunityTasks is not installed. In those cases the version number in GlobalAssemblyInfo.cs is left untouched.
<Target Name="InjectSVNRevision" Condition="Exists('$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets')">
<!-- When this build is done by the Jenkins CI server; the svn revision number is set in the environment variable SVN_REVISION
This little snippet replaces the revision number in GlobalAssemblyInfo.cs with this svn revision number
-->
<Message Text="Injecting SVN revision number in GlobalAssemblyInfo.cs" />
<FileUpdate Files="GlobalAssemblyInfo.cs"
Multiline="true"
Singleline="false"
Regex="(AssemblyVersion|AssemblyFileVersionAttribute|AssemblyFileVersion)\("([0-9]+\.[0-9]+\.[0-9]+)(\.[0-9]+)?"\)"
ReplacementText="$1("$2.$(SVN_REVISION)")"
Condition="$(SVN_REVISION) != '' "/>
</Target>