Incrementing build number with Hudson build

Here is what I am trying to achieve. I currently use Hudson build to do builds for me on a remote computer. I currently have to open my solution and manually update the [assembly: AssemblyVersion("1.2.6.190")] numbers in two files and then commit my changes to SVN before running the build through Hudson. (the hudson job is not set to run unless you clcik build now)

I would like to find a way to automatically increment only the last number every time Hudson does a build.

I would like it to increment by 1 (not timestamped or similar).

Any ideas or links to other material that may help would be appreciated =)

Thanks,

Toby


我使用Jenkins的PowerShell插件并使用Powershell来查找所有符合模式的文件(比如AssemblyInfo。*),然后读取这些文件并使用PowerShell中的内置正则表达式功能(-match和-replace操作)查找并替换AssemblyVersion属性,将最后一个八位字节更改为当前的Jenkins内部版本号。

function assign-build-number
{
    #get the build number form Jenkins env var
    if(!(Test-Path env:BUILD_NUMBER))
    {
        return
    }

    #set the line pattern for matching
    $linePattern = 'AssemblyFileVersion'
    #get all assemlby info files
    $assemblyInfos = gci -path $env:ENLISTROOT -include AssemblyInfo.cs -Recurse

    #foreach one, read it, find the line, replace the value and write out to temp
    $assemblyInfos | foreach-object -process {
        $file = $_
        write-host -ForegroundColor Green "- Updating build number in $file"
        if(test-path "$file.tmp" -PathType Leaf)
        {
            remove-item "$file.tmp"
        }
        get-content $file | foreach-object -process {
            $line = $_
            if($line -match $linePattern)
            {
                #replace the last digit in the file version to match this build number.
                $line = $line -replace 'd"', "$env:BUILD_NUMBER`""
            }

            $line | add-content "$file.tmp"

        }
        #replace the old file with the new one
        remove-item $file
        rename-item "$file.tmp" $file -Force -Confirm:$false
   }
}

Since I only got answers that did not take into account my requirements of using Hudson I thought I would post a link to a good solution.

Take a look at the answer by "nos" here - How can I auto increment the C# assembly version via our CI platform (Hudson)?

It's not the accepted answer but it should be as it works perfectly.

链接地址: http://www.djcxy.com/p/50672.html

上一篇: 修正了自动递增文件版本的组装版本?

下一篇: 用哈德森版本增加版本号