Created
February 24, 2015 16:41
-
-
Save Dalmirog-zz/fe931fc28a6f215974f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Encode-ServiceMessageValue([string]$value) | |
{ | |
$valueBytes = [System.Text.Encoding]::UTF8.GetBytes($value) | |
return [Convert]::ToBase64String($valueBytes) | |
} | |
function Set-OctopusVariable([string]$name, [string]$value) | |
{ | |
$name = Encode-ServiceMessageValue($name) | |
$value = Encode-ServiceMessageValue($value) | |
Write-Host ""##octopus[setVariable name='$name' value='$value']"" | |
} | |
function New-OctopusArtifact([string]$path) | |
{ | |
$originalFilename = [System.IO.Path]::GetFileName($path) | |
$originalFilename = Encode-ServiceMessageValue($originalFilename) | |
$path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($path) | |
$path = [System.IO.Path]::GetFullPath($path) | |
$path = Encode-ServiceMessageValue($path) | |
Write-Output ""##octopus[createArtifact path='$path' originalFilename='$originalFilename']"" | |
} | |
function Enable-OctopusOutputBuffer([string]$operation) | |
{ | |
$operation = Encode-ServiceMessageValue($operation) | |
Write-Output ""##octopus[enableBuffer operation='$operation']"" | |
} | |
function Disable-OctopusOutputBuffer() | |
{ | |
Write-Output ""##octopus[disableBuffer]"" | |
} | |
# Some of this code for reading environment variables comes from Chocolatey, under the Apache II license | |
# https://github.com/chocolatey/chocolatey/blob/master/LICENSE | |
function Get-EnvironmentVariableNames([System.EnvironmentVariableTarget] $Scope) | |
{ | |
try { | |
switch ($Scope) { | |
'User' { Get-Item 'HKCU:\Environment' | Select-Object -ExpandProperty Property } | |
'Machine' { Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' | Select-Object -ExpandProperty Property } | |
'Process' { Get-ChildItem Env:\ | Select-Object -ExpandProperty Key } | |
default { throw ""Unsupported environment scope: $Scope"" } | |
} | |
} | |
catch [system.exception] | |
{ | |
return $Null | |
} | |
} | |
function Get-EnvironmentVariable([string] $Name, [System.EnvironmentVariableTarget] $Scope) | |
{ | |
return [Environment]::GetEnvironmentVariable($Name, $Scope) | |
} | |
function Set-EnvVariable($Name, $Value) | |
{ | |
if ($Value -Ne $Null) { | |
Set-Item ""Env:$Name"" -Value $Value | |
} | |
} | |
function Update-SessionEnvironmentVariables() | |
{ | |
$scopes = 'Machine', 'User' | |
$scopes | | |
% { | |
$scope = $_ | |
Get-EnvironmentVariableNames -Scope $scope | | |
% { | |
if(($_ -ne 'TEMP') -and ($_ -ne 'TMP')){ | |
$val = Get-EnvironmentVariable -Scope $scope -Name $_ | |
Set-Item ""Env:$_"" -Value $val | |
} | |
} | |
} | |
# Path gets special treatment as it combines the two together | |
$paths = $scopes | | |
% { (Get-EnvironmentVariable -Name 'PATH' -Scope $_) -Split ';' } | | |
Select -Unique | |
$Env:PATH = ($paths -join ';') | |
} | |
$ConfirmPreference = ""None"" | |
$ErrorActionPreference = ""Stop"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment