2

这是我想要实现的目标。我目前使用 Hudson build 在远程计算机上为我进行构建。我目前必须打开我的解决方案并手动更新两个文件中的 [assembly: AssemblyVersion("1.2.6.190")] 编号,然后在通过 Hudson 运行构建之前将我的更改提交到 SVN。(除非您现在 clcik 构建,否则 hudson 作业不会运行)

我想找到一种方法,每次 Hudson 进行构建时只自动增加最后一个数字。

我希望它增加 1(没有时间戳或类似)。

任何可能有帮助的想法或其他材料的链接将不胜感激=)

谢谢,

托比

4

1 回答 1

5

我使用 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
   }
}
于 2011-11-07T14:12:04.927 回答