1
votes

I have just set up C.I with Jenkins using the declarative pipepline approach. It's working fine now but I'd like to set the assembly revision number to the Build Number used by Jenkins.

I see that there's a plugin called change-assembly-version-plugin but it seems to be the old way of doing things and I'm not sure how it can be used in a Jenkinsfile.

Any pointers on how I can achieve this would be really appreciated.

1
It's not a duplicate because that post is describing how to use the plugin when not using declarative pipelines. I do not have access to the plugin settings from what I can seeJohn Mc

1 Answers

1
votes

This is an old plugin that is not compatible with Pipelines (see Pipeline Compatible Plugins).

As an alternative use a "bat" (batch) block with command-line utility (eg. SED) or "powershell" block script to manipulate your AssemblyInfo.cs file.

Manipulation will become easier if you move the AssemblyFileVersion and AssemblyVersion properties into a separate "CustomVersion.cs" file, then just rewrite it from a pipeline "bat" block. Something like:

bat """
    @echo off
    echo using System.Reflection; >CustomVersion.cs
    echo using System.Resources; >>CustomVersion.cs
    echo [assembly: AssemblyVersion("1.2.%BUILD_NUMBER%.0")] >>CustomVersion.cs
    echo [assembly: AssemblyFileVersion("1.2.%BUILD_NUMBER%.0")] >>CustomVersion.cs
"""

The above code should work with scripted pipelines, not sure about declarative pipelines.