How to set assembly version to Jenkins build number?

大憨熊 提交于 2019-12-18 12:37:12

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/33496781/how-to-set-assembly-version-to-jenkins-build-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!