カスタムパワーシェルスクリプトを使用しています。
ビルドタスクでは、リリースタスクで必要な変数を含むXMLファイルを作成します。 XMLファイルは後でArtifactの一部です。
私は、変数名と現在の値、XMLファイルへのパスと私のカスタムスクリプトを呼び出すすべてのだから、最初:PowerShellスクリプトは、このようなものです
。
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のノード名です。
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"
[ここ]を見ている(https://lajak.wordpress.com/2011/03/ 13/pass-relative-path-arguments-to-msbuild-in-tfs2010-team-build /)、それが役に立っているかどうかを確認してください – lokusking
こんにちはlokusking、私は新しいスクリプトベースのリリース管理を使用しています。申し訳ありませんが私はそれを言及していない。 – Chris