0

I build my first model in Jenkins, I tried to get the svn revision by the variable SVN_REVISION but it does not work.

I need it to set it in my assemblyInfo files.

I made a search in google and got nothig.

Please help me!

Ped7g
  • 16,236
  • 3
  • 26
  • 63
Yos
  • 41
  • 1
  • 6

1 Answers1

0

You could use flubu that we wrote. Flubu is A C# library for building projects and executing deployment scripts using C# code.

More about flubu can be found here: Choice for build tool: MSBuild, NANT or something else?

For your particular case you'd have to Generate CommonAssemblyInfo or update each AssemblyInfo info with custom task. I'll give you example how to do it with CommonAssemblyInfo:

public class BuildScript : DefaultBuildScript
 {
        protected override void ConfigureBuildProperties(IBuildPropertiesContext context)
        {
            context.Properties.Set(BuildProps.CompanyName, "Company");

            context.Properties.Set(BuildProps.ProductId, "ProductId");
            context.Properties.Set(BuildProps.ProductName, "ProductName");
            context.Properties.Set(BuildProps.SolutionFileName, @"Solution.sln");
            context.Properties.Set(BuildProps.BuildConfiguration, "Release");
        }

        protected override void ConfigureTargets(ITaskContext context)
        {
            var loadSolution = context.CreateTarget("load.solution")
                .SetDescription("Load & analyze VS solution")
                .AddTask(x => x.LoadSolutionTask())
                .SetAsHidden();

            var fetchVersion = context.CreateTarget("fetch.version")
                .SetDescription("Fetch the build version")
                .Do(TargetFetchBuildVersion);

            var generateCommonAssInfo = context.CreateTarget("generate.commonAssInfo")
             .DependsOn(fetchVersion)
             .TaskExtensions()
                .GenerateCommonAssemblyInfo()
                .BackToTarget();

           var compile = context.CreateTarget("compile")
                .AddTask(x => x.CompileSolutionTask())
                .DependsOn(loadSolution, generateCommonAssInfo);
        }

        public static void TargetFetchBuildVersion(ITaskContext context)
        {
            var version = context.Tasks().FetchBuildVersionFromFileTask().Execute(context);
            string svnRevisionNumberString = Environment.GetEnvironmentVariable("SVN_REVISION");
            int svnRevisionNumber = 0;

            if (!string.IsNullOrEmpty(svnRevisionNumberString))
            {
                svnRevisionNumber = int.Parse(svnRevisionNumberString, CultureInfo.InvariantCulture);
            }

            version = new Version(version.Major, version.Minor, version.Build, svnRevisionNumber);
            context.Properties.Set(BuildProps.BuildVersion, version);
        }
}

Then you would run the script with flubu runner in cmd or jenkins as build step: build.exe compile

You have to include generated CommonAssemblyInfo into each project offcourse.

Stan88
  • 252
  • 3
  • 12