I am using "Change Assembly Version" plug-in in Jenkins to update all AssemblyInfo.cs files of my ASP.NET MVC project to apply version number during build process. If I set the "Assembly Version" value to a hard-coded one, this works very well.
But my requirement is different - I would want to use a build number in the version number. For example, "1.1.0.25", where 25 is the build number and auto-generated by Jenkins. In short, the versions should be like "1.1.0.<>"
I could do this in TFS build process using TFS environment variables, I am new in Jenkins, and not sure how can we achieve this in Jenkins.
Following is a screenshot of "Change Assembly Version" plug-in from Jenkins for your quick reference:
Thanks in advance
The previous answer about how to use "Change Assembly Version" plugin for Jenkins doesn't work.
In my AssemblyInfo.cs files I usually set them up with auto incrementing version to help local dev work.
Example
AssemblyInfo.cs contains:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
After the Jenkins build if the version is 10 then AssemblyInfo.cs will contain:
[assembly: AssemblyVersion("1.0.10")]
[assembly: AssemblyFileVersion("1.0.10")]
The plugin is used like so to achieve the above:
Assembly Version: $BUILD_NUMBER
FileName:
RegexPattern: Assembly(\w*)Version\("(\d+).(\d+).(\*)"\)
ReplacementPattern: Assembly$1Version("$2.$3.%s")
One other error I got whilst using the plugin was the file permission didn't allow write access. In order to fix this find the AssemblyInfo.cs and disable "Read Only".
Hope to helps anyone.
For others looking to update just 1 number of the version number but keep the rest of the existing version numbers you can set up the "Change Assembly Version" plug-in as follows:
Assembly Version: $BUILD_NUMBER
FileName: <project folder>/Properties/AssemblyInfo.cs
RegexPattern: Assembly(\w*)Version\("(\d+).(\d+).(\d+).(\d+)"\)
ReplacementPattern: Assembly$1Version("$2.$3.%s")
This will keep the existing, first 2 numbers already contained in the Assembly???Version settings and set the 3rd version number to the current Jenkins build number.
Example
AssemblyInfo.cs contains:
[assembly: AssemblyVersion("1.40.0.0")]
[assembly: AssemblyFileVersion("1.40.0.0")]
If the Jenkins build number is 103, then after the above settings are used by the Change Assembly Version plugin the AssemblyInfo.cs will contain:
[assembly: AssemblyVersion("1.40.103.0")]
[assembly: AssemblyFileVersion("1.40.103.0")]
Note
If you are using subversion (and likely other source control systems) and are using the "Check-out Strategy" of "Use SVN update as much as possible" you will have to change it to "Use SVN update as much as possible with svn revert before update" to ensure that the modified AssemblyInfo.cs file is reset for the next build.
Cool, I found the answer myself.
basically, I had to give "1.0.0.$BUILD_NUMBER" in the "Assembly Version" field of the "Change Assembly Version" plugin
I had to do this recently without the "Change Assembly Version" plug-in. I just used a PowerShell script instead. I'll post it here as it may offer a bit more flexibility for those that want it:
if (Test-Path env:BUILD_NUMBER) {
Write-Host "Updating AssemblyVersion to $env:BUILD_NUMBER"
# Get the AssemblyInfo.cs
$assemblyInfo = Get-Content -Path .\MyShinyApplication\Properties\AssemblyInfo.cs
# Replace last digit of AssemblyVersion
$assemblyInfo = $assemblyInfo -replace
"^\[assembly: AssemblyVersion\(`"([0-9]+)\.([0-9]+)\.([0-9]+)\.[0-9]+`"\)]",
('[assembly: AssemblyVersion("$1.$2.$3.' + $env:BUILD_NUMBER + '")]')
Write-Host ($assemblyInfo -match '^\[assembly: AssemblyVersion')
# Replace last digit of AssemblyFileVersion
$assemblyInfo = $assemblyInfo -replace
"^\[assembly: AssemblyFileVersion\(`"([0-9]+)\.([0-9]+)\.([0-9]+)\.[0-9]+`"\)]",
('[assembly: AssemblyFileVersion("$1.$2.$3.' + $env:BUILD_NUMBER + '")]')
Write-Host ($assemblyInfo -match '^\[assembly: AssemblyFileVersion')
$assemblyInfo | Set-Content -Path .\MyShinyApplication\Properties\AssemblyInfo.cs -Encoding UTF8
} else {
Write-Warning "BUILD_NUMBER is not set."
}
Related
We are using TFS and nexus package manager. For the CI we have Nuget Publisher task.
For the Path/Pattern to nupkg I wrote: "^((?!SNAPSHOT).)*nupkg;-:**/packages/^((?!SNAPSHOT).)*nupkg;-:^((?!SNAPSHOT).)*nupkg"
I want to say take nupkg files which do not contain SNAPSHOT in the file name.
1-C:_work\2\s\test-project.1.0.1-SNAPSHOT-umut.nupkg
2-C:_work\2\s\test-project.1.0.1.nupkg
I want to take the second file.
But when I start the build, I get the error:
Starting: NuGet Publisher
******************************************************************************
==============================================================================
Task : NuGet Publisher
Description : Deprecated: use the “NuGet” task instead. It works with the new Tool Installer framework so you can easily use new versions of NuGet without waiting for a task update, provides better support for authenticated feeds outside this account/collection, and uses NuGet 4 by default.
Version : 0.2.37
Author : Lawrence Gripper
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=627417)
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Error: No matching files were found with search pattern: C:\_work\2\s\**\*^((?!SNAPSHOT).)*nupkg;-:**\packages\**\*^((?!SNAPSHOT).)*nupkg;-:**\*^((?!SNAPSHOT).)*nupkg
Packages failed to publish
******************************************************************************
Finishing: NuGet Publisher
Path/Pattern to nupkg argument doesn't support ! wildcard, it supports:
You need to use powershell script to filter and publish the packages.
#TetraDev in this post provides a powershell script to bulk push NuGet packages to a VSTS feed. It will ignore any of the .symbols.nuget files:
set-location \\path\to\nugetpackages
$files=get-childitem | where {$_.Name -like "*.nupkg" -and $_.Name -notlike "*symbols*"}
foreach($file in $files) {
.\NuGet.exe push -Source "MySource" -ApiKey key $file.name
}
I'm using "TFS 2018 Update 2" and trying to build a package marked as a pre-release according to the microsoft semantic
I tried using the .nuspec file inserting the (ex: 1.0.0-beta and changing the Build number format as: $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)$(Suffix)
setting the $(Suffix) variable at queue time.
Every attempt failed: the package never contains the suffix, than is never marked as pre-release.
I see that the nuget pack command never contains the suffix (missing "-beta" after "2018.6.12.9"). In my test build $Suffix is set to "-beta":
nuget.exe pack
C:\agent_work\4\s\DotNetClassicLibrary\DotNetClassicLibrary.csproj
-NonInteractive -OutputDirectory C:\agent_work\4\a -Properties Configuration=debug -version 2018.6.12.9 -Verbosity Detailed
The Build task on TFS is:
"DotNetClassicLibrary / Build DotNetClassicLibrary_2018.6.12.9-beta /
Job / NuGet pack"
So I'm sure that the variable is assigned because of the presence of the suffix "-beta" in the path.
Here there is the configuration of the nuget pack task
This is the Build number format
I could reproduce your scenario on my side. In my opinion, Nuget pack task with build number doesn't support character or numbers. You may check this task and try to modify it.
case "byBuildNumber":
tl.debug("Getting version number from build number")
if(tl.getVariable("SYSTEM_HOSTTYPE") === "release")
{
tl.setResult(tl.TaskResult.Failed, tl.loc("Error_AutomaticallyVersionReleases"));
return;
}
let buildNumber: string = tl.getVariable("BUILD_BUILDNUMBER");
tl.debug(`Build number: ${buildNumber}`);
let versionRegex = /\d+\.\d+\.\d+(?:\.\d+)?/;
let versionMatches = buildNumber.match(versionRegex);
if (!versionMatches)
{
tl.setResult(tl.TaskResult.Failed, tl.loc("Error_NoVersionFoundInBuildNumber"));
return;
}
if (versionMatches.length > 1)
{
tl.warning(tl.loc("Warning_MoreThanOneVersionInBuildNumber"))
}
version = versionMatches[0];
break;
As an alternative, you could choose Nuget custom, and specify the
pack command there with parameter -version $(Build.BuildNumber),
I've tried on my side, this works.
I use Delphi XE4 on Windows7 and use Microsoft.NET/Framework/V3.5/MSBuild.exe .
I have added the MSBuild path to the environment variable.
But got this error :(
$MSBuild.exe Project3.dproj /target:Build /property:configutation=Debug
Microsoft (R) Build Engine Version 3.5.30729.5420
[Microsoft .NET Framework, Version 2.0.50727.8762]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 2017/10/30 ▒W▒▒ 10:45:40.
Project "C:\DXE4_LangDLL\Project3.dproj" on node 0 (Build target(s)).
C:\DXE4_LangDLL\Project3.dproj : error MSB4057: The target "Build" does not exist in the project.
Done Building Project "C:\DXE4_LangDLL\Project3.dproj" (Build target(s)) -- FAILED.
Build FAILED.
"C:\DXE4_LangDLL\Project3.dproj" (Build target) (1) ->
C:\DXE4_LangDLL\Project3.dproj : error MSB4057: The target "Build" does not exist in the project.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.00
I tried use Microsoft.NET/Framework/V2.0.50727/MSBuild.exe and got the same message.
I was confuse because used Delphi IDE to build project successfully.
Can someone help me?
You have to set first the environmental variables. There is a batch file, at the path
C:\Program Files (x86)\Embarcadero\Studio\XX\rsvars.bat
that i use for command-line batch files, where XX the version of your RAD Studio.
I am not sure if it will work for Git bash as it is, but you can create a batch file that will combine the lines of rsvars.bat and the MSBuild line, and execute it
Something like:
#SET BDS=C:\Program Files (x86)\Embarcadero\Studio\XX
#SET BDSINCLUDE=C:\Program Files (x86)\Embarcadero\Studio\XX\include
#SET BDSCOMMONDIR=C:\Users\Public\Documents\Embarcadero\Studio\XX
#SET FrameworkDir=C:\Windows\Microsoft.NET\Framework\v3.5
#SET FrameworkVersion=v3.5
#SET FrameworkSDKDir=
#SET PATH=%FrameworkDir%;%FrameworkSDKDir%;C:\Program Files (x86)\Embarcadero\Studio\XX\bin;C:\Program Files (x86)\Embarcadero\Studio\XX\bin64;C:\Users\Public\Documents\Embarcadero\InterBase\redist\InterBaseXE3\IDE_spoof;%PATH%
#SET LANGDIR=EN
#SET PLATFORM=
#SET PlatformSDK=
$MSBuild.exe Project3.dproj /target:Build /property:configutation=Debug
The SpecFlow sample documentation has a show link next to the scenario which I assume shows the steps.
When I generate my report I don't have this link.
I runt the tests and generate the report as follows using Visual Studio 2017 and .NET Framework 4.6.2
%solution_root%packages\NUnit.ConsoleRunner.3.6.1\tools\nunit3-console.exe
--labels=All --out=output.txt "--result=output.xml;format=nunit2" SystemIntegration.Test.dll
%solution_root%packages\SpecFlow.2.1.0\tools\specflow.exe
nunitexecutionreport %project_file% /xmlTestResult:output.xml
/testOutput:output.txt /out:report.html
So, apparently the output.txtneeds to be in the nunit2 format as well but format=nunit2 does not work on that arg. To update the .txt file I added a powershell command to replace => with ***** in the output text file before running the execution report.
powershell -command "(get-content 'output.txt') | ForEach-Object { $_ -replace '=>', '*****' } | Set-Content 'output.txt'"
Note: this is fixed in SpecFlow code but not yet released. Will update this answer when fix is available.
I am trying to get Hudson to work with my Delphi project. I am using the following batch file to build my project (as suggested in this blog post):
call "C:\Program Files\Embarcadero\RAD Studio\8.0\bin\rsvars.bat"
msbuild /p:Win32LibraryPath="$(BDS)\lib;$(BDS)\lib\win32\release;$(BDS)\lib\win32\debug;$(BDSUSERDIR)\Imports;$(BDS)\Imports;$(BDSCOMMONDIR)\Dcp;$(BDS)\include;" /t:build /p:config=Debug /verbosity:detailed "MyProject\src\MyProject.dproj"
if errorlevel 1 exit 1
I always end up with the error
Embarcadero Delphi for Win32 compiler version 22.0
Copyright (c) 1983,2010 Embarcadero Technologies, Inc.
Fatal: E2202 Required package 'rtl' not found
I don't understand this as rtl.dcp is in "$(BDS)\lib\win32\release" which is on the library path. I am using runtime packages by the way.
Any hints what I can do to solve this?
Edit It seems that the paths do not end up in the command line, which looks something like (after removing project-specific paths):
C:\Program Files\Embarcadero\RAD Studio\8.0\bin\dcc32.exe -$O- -$W+ --inline:off -$A4 -$R+ -$Q+ --doc --no-config -B -LUrtl;vcl;ReportingR;ComponentsR -Q -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE -DDEBUG;CONSTRAINT_CHECKING;_VER6;EUREKALOG_VER6;EurekaLog -V -VN -GD --drc -W-SYMBOL_DEPRECATED -W-SYMBOL_PLATFORM -W-UNIT_PLATFORM -W-UNIT_DEPRECATED Myproject.dpr
I found the answer in a comment to the original blog post. It turns out that in Delphi XE they changed the name of the Win32LibraryPath property to DelphiWin32LibraryPath. Changing the batch script accordingly fixes the issue.
The first path $(BDS)\Lib for XE,XE2 and XE 10.2 should be change for $(BDSLIB)\$(PLATFORM)\release