2

これが私が達成しようとしていることです。現在、Hudson ビルドを使用して、リモート コンピューターでビルドを行っています。現在、ソリューションを開いて [assembly: AssemblyVersion("1.2.6.190")] の番号を 2 つのファイルで手動で更新し、Hudson でビルドを実行する前に変更を SVN にコミットする必要があります。(今ビルドをクリックしない限り、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 に答える