XML Transform using XDT

Octopus.Script exported 2016-08-24 by lijunkang belongs to ‘XML’ category.

You can use this script to easily transform any XML file using XDT. The script will download its dependencies automatically.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Source file path

sourceFile

null

Transform file path

transformFile

null

Destination file path

destFile

null

Directory to download tools programs

toolsDir = C:\tools

null

Script body

Steps based on this template will execute the following PowerShell script.

function Get-Parameter($Name, $Default, [switch]$Required) {
    $result = $null

    if ($OctopusParameters -ne $null) {
        $result = $OctopusParameters[$Name]
    }

    if ($result -eq $null) {
        if ($Required) {
            throw "Missing parameter value $Name"
        } else {
            $result = $Default
        }
    }

    return $result
}

$toolsDir = Get-Parameter "toolsDir" -Required
$sourceFile = Get-Parameter "sourceFile" -Required
$transformFile = Get-Parameter "transformFile" -Required
$destFile = Get-Parameter "destFile" -Required

if(!(Test-Path $toolsDir)){
    New-Item -Path $toolsDir -ItemType Directory
}
$nugetDestPath = Join-Path -Path $toolsDir -ChildPath nuget.exe
if(!(Test-Path $nugetDestPath)){
    Write-Output 'Downloading nuget.exe'
	# download nuget
    Invoke-WebRequest 'http://nuget.org/nuget.exe' -OutFile $nugetDestPath
    # double check that it was written to disk
    if(!(Test-Path $nugetDestPath)){
        throw 'unable to download nuget'
    }
}

$xdtExe = (Get-ChildItem -Path $toolsDir -Include 'SlowCheetah.Xdt.exe' -Recurse) | Select-Object -First 1

if(!$xdtExe){
    Write-Output 'Downloading xdt since it was not found in the tools folder'
     # nuget install SlowCheetah.Xdt -Prerelease -OutputDirectory toolsDir\
    $nugetInstallCmdArgs = @('install','SlowCheetah.Xdt','-Prerelease','-OutputDirectory',(Resolve-Path $toolsDir).ToString())

    Write-Output ('Calling nuget.exe to download SlowCheetah.Xdt with the following args: [{0} {1}]' -f $nugetDestPath, ($nugetInstallCmdArgs -join ' '))
    &($nugetDestPath) $nugetInstallCmdArgs

    $xdtExe = (Get-ChildItem -Path $toolsDir -Include 'SlowCheetah.Xdt.exe' -Recurse) | Select-Object -First 1

    if(!$xdtExe){
        throw ('SlowCheetah.Xdt not found')
    }

    # copy the xdt assemlby if the xdt directory is missing it
    $xdtDllExpectedPath = (Join-Path $xdtExe.Directory.FullName 'Microsoft.Web.XmlTransform.dll')

    if(!(Test-Path $xdtDllExpectedPath)){
        # copy the xdt.dll next to the slowcheetah .exe
        $xdtDll = (Get-ChildItem -Path $toolsDir -Include 'Microsoft.Web.XmlTransform.dll' -Recurse) | Select-Object -First 1

        if(!$xdtDll){
		    throw 'Microsoft.Web.XmlTransform.dll not found'
		}

        Copy-Item -Path $xdtDll.Fullname -Destination $xdtDllExpectedPath
    }
}

$cmdArgs = @((Resolve-Path $sourceFile).ToString(),
            (Resolve-Path $transformFile).ToString(),
            (Resolve-Path $destFile).ToString())

Write-Output ('Calling slowcheetah.xdt.exe with the args: [{0} {1}]' -f $xdtExe, ($cmdArgs -join ' '))
&($xdtExe) $cmdArgs

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "569a5f1b-bb57-491a-9c4e-a6d6e44e6b26",
  "Name": "XML Transform using XDT",
  "Description": "You can use this script to easily transform any XML file using XDT.\nThe script will download its dependencies automatically.",
  "Version": 8,
  "ExportedAt": "2016-08-24T07:11:46.726+00:00",
  "ActionType": "Octopus.Script",
  "Author": "lijunkang",
  "Parameters": [
    {
      "Name": "sourceFile",
      "Label": "Source file path",
      "HelpText": null,
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "transformFile",
      "Label": "Transform file path",
      "HelpText": null,
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "destFile",
      "Label": "Destination file path",
      "HelpText": null,
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "toolsDir",
      "Label": "Directory to download tools programs",
      "HelpText": null,
      "DefaultValue": "C:\\tools",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.ScriptBody": "function Get-Parameter($Name, $Default, [switch]$Required) {\n    $result = $null\n\n    if ($OctopusParameters -ne $null) {\n        $result = $OctopusParameters[$Name]\n    }\n\n    if ($result -eq $null) {\n        if ($Required) {\n            throw \"Missing parameter value $Name\"\n        } else {\n            $result = $Default\n        }\n    }\n\n    return $result\n}\n\n$toolsDir = Get-Parameter \"toolsDir\" -Required\n$sourceFile = Get-Parameter \"sourceFile\" -Required\n$transformFile = Get-Parameter \"transformFile\" -Required\n$destFile = Get-Parameter \"destFile\" -Required\n\nif(!(Test-Path $toolsDir)){\n    New-Item -Path $toolsDir -ItemType Directory\n}\n$nugetDestPath = Join-Path -Path $toolsDir -ChildPath nuget.exe\nif(!(Test-Path $nugetDestPath)){\n    Write-Output 'Downloading nuget.exe'\n\t# download nuget\n    Invoke-WebRequest 'http://nuget.org/nuget.exe' -OutFile $nugetDestPath\n    # double check that it was written to disk\n    if(!(Test-Path $nugetDestPath)){\n        throw 'unable to download nuget'\n    }\n}\n\n$xdtExe = (Get-ChildItem -Path $toolsDir -Include 'SlowCheetah.Xdt.exe' -Recurse) | Select-Object -First 1\n\nif(!$xdtExe){\n    Write-Output 'Downloading xdt since it was not found in the tools folder'\n     # nuget install SlowCheetah.Xdt -Prerelease -OutputDirectory toolsDir\\\n    $nugetInstallCmdArgs = @('install','SlowCheetah.Xdt','-Prerelease','-OutputDirectory',(Resolve-Path $toolsDir).ToString())\n\n    Write-Output ('Calling nuget.exe to download SlowCheetah.Xdt with the following args: [{0} {1}]' -f $nugetDestPath, ($nugetInstallCmdArgs -join ' '))\n    &($nugetDestPath) $nugetInstallCmdArgs\n\n    $xdtExe = (Get-ChildItem -Path $toolsDir -Include 'SlowCheetah.Xdt.exe' -Recurse) | Select-Object -First 1\n\n    if(!$xdtExe){\n        throw ('SlowCheetah.Xdt not found')\n    }\n\n    # copy the xdt assemlby if the xdt directory is missing it\n    $xdtDllExpectedPath = (Join-Path $xdtExe.Directory.FullName 'Microsoft.Web.XmlTransform.dll')\n\n    if(!(Test-Path $xdtDllExpectedPath)){\n        # copy the xdt.dll next to the slowcheetah .exe\n        $xdtDll = (Get-ChildItem -Path $toolsDir -Include 'Microsoft.Web.XmlTransform.dll' -Recurse) | Select-Object -First 1\n\n        if(!$xdtDll){\n\t\t    throw 'Microsoft.Web.XmlTransform.dll not found'\n\t\t}\n\n        Copy-Item -Path $xdtDll.Fullname -Destination $xdtDllExpectedPath\n    }\n}\n\n$cmdArgs = @((Resolve-Path $sourceFile).ToString(),\n            (Resolve-Path $transformFile).ToString(),\n            (Resolve-Path $destFile).ToString())\n\nWrite-Output ('Calling slowcheetah.xdt.exe with the args: [{0} {1}]' -f $xdtExe, ($cmdArgs -join ' '))\n&($xdtExe) $cmdArgs\n",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.NuGetFeedId": null,
    "Octopus.Action.Package.NuGetPackageId": null
  },
  "Category": "XML",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/xml-transform-using-xdt.json",
  "Website": "/step-templates/569a5f1b-bb57-491a-9c4e-a6d6e44e6b26",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAACOlJREFUeNrsnc1TE2cYwNVhhnAinDb0QAIHsTBDsM4AVSvUj2qtDE6njh60emhr/512pnetPejQ6ehgrYxfBGurzlDBGZF4wMQDSU4kNzjRR2Ip7ru7+XoT8m5+v+MGdpN3f3me5/3abF9bW9sGoJsdNAEgFiAWIBYAYgFiAWIBIBYgFiAWAGIBYgFiASAWI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71atZ7avra3pOtfVa+Px+CvKC41c/O6bUMjSdbap2HQs9tDt1eHhT0aGD9Rj8d4f7UMFjViWpdEqg3uFu3Z1t7a2IoQuhoYM/l0dzcMNx44eQQhd4croDKBZLAla3d070aJyTP+pph3VaBHLsjCjEsbGRs2trqolViAQELeam5vxozwGBwd80A2qypSOfNu+v/gtcau8WOWPOrVac4XBYOuF82cH/fJ7oTVAOtTnvz7rmyGbKq5ukJwoX75d3TunYtP8aIW3Uv39fRoHJ30uVp5IJHwhci6bzS3E4wsLcQzbPKAgNYN88aQr7b9PV6P1WJIZhwYHNn5JO53OeDxk5vbkHY8H5x89eiRkePUmPvn+qRBNW9WynjnUq0cpVpk7Nds47KAJALEAsQCxABALEAsQCwCxALEAsQAQCxALEAsAsQCxALEAtNBk3Du+/PMv3DYiFiAWAGIBYgFiQQOjd1NdPYrlyw2cBogVCvldrO5uHlZTY8LhjmCw1ediySc8duwz3KoZlmWdOX1K7zl1PjVZL9lsbio2nUgkc7kc9756gSoSCQ8NDmjf8l+/YgG9QgDEAsQCxAJALEAsQCwAxALEAsQCQCxALEAsAMQCxALEAkAsQCxALEAsAMQCU/hXgAEAvqSVJBhJrL4AAAAASUVORK5CYII=",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Wednesday, August 24, 2016