2016-08-22 8 views
7

TFS 2015には、自動的に新しいリリースがトリガーされるビルドがあります。 新しいscript based build definitionsで実現されています。TFS 2015リリース管理アクセスビルド変数

ここで、ユーザー変数をビルドからリリースに渡したいとします。 ビルドで変数 "Branch"を作成しました。私はそれにアクセスしようと自動的にトリガーリリースで

enter image description here

。しかし、それは常に空です/設定されていません。

$(Branch)$(Build.Branch)で試しました。 私はまた、これらの名前でリリースで変数を作成しようとしましたが、成功しませんでした。

リリースのビルド定義からユーザー変数にアクセスする可能性はありますか?

+0

[ここ]を見ている(https://lajak.wordpress.com/2011/03/ 13/pass-relative-path-arguments-to-msbuild-in-tfs2010-team-build /)、それが役に立っているかどうかを確認してください – lokusking

+0

こんにちはlokusking、私は新しいスクリプトベースのリリース管理を使用しています。申し訳ありませんが私はそれを言及していない。 – Chris

答えて

4

カスタムパワーシェルスクリプトを使用しています。

ビルドタスクでは、リリースタスクで必要な変数を含むXMLファイルを作成します。 XMLファイルは後でArtifactの一部です。

私は、変数名と現在の値、XMLファイルへのパスと私のカスタムスクリプトを呼び出すすべてのだから、最初:PowerShellスクリプトは、このようなものです

enter image description here

Param 
(
    [Parameter(Mandatory=$true)] 
    [string]$xmlFile, 

    [Parameter(Mandatory=$true)] 
    [string]$variableName, 

    [Parameter(Mandatory=$true)] 
    [string]$variableValue 
) 

$directory = Split-Path $xmlFile -Parent 
If (!(Test-Path $xmlFile)){ 
    If (!(Test-Path $directory)){ 
    New-Item -ItemType directory -Path $directory 
    } 
    Out-File -FilePath $xmlFile 
    Set-Content -Value "<Variables/>" -Path $xmlFile 
} 

$xml = [System.Xml.XmlDocument](Get-Content $xmlFile); 
$xml["Variables"].AppendChild($xml.CreateElement($variableName)).AppendChild($xml.CreateTextNode($variableValue)); 
$xml.Save($xmlFile) 

これは、このようなXMLになります:

<Variables> 
    <Branch>Main</Branch> 
</Variables> 

それは人工物の一部となるように、それから私は、アーティファクトのステージングディレクトリにコピーします。

リリースタスクでは、別のpowershellスクリプトを使用して、xmlを読み取ってタスク変数を設定します。

最初のパラメータはxmlファイルの位置、2番目のタスク変数(リリース管理で変数を作成する必要があります)、最後はxmlのノード名です。

enter image description here

XMLを読み込んで変数を設定するには、PowerShellは、このようなものです:

Param 
(
    [Parameter(Mandatory=$true)] 
    [string]$xmlFile, 

    [Parameter(Mandatory=$true)] 
    [string]$taskVariableName, 

    [Parameter(Mandatory=$true)] 
    [string]$xmlVariableName 
) 

$xml = [System.Xml.XmlDocument](Get-Content $xmlFile); 
$value = $xml["Variables"][$xmlVariableName].InnerText 

Write-Host "##vso[task.setvariable variable=$taskVariableName;]$value" 
関連する問題