-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into users/nidabas/removePublishMetadataVar
- Loading branch information
Showing
58 changed files
with
2,114 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 158, | ||
"Patch": 0 | ||
"Patch": 1 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 158, | ||
"Patch": 0 | ||
"Patch": 1 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 154, | ||
"Patch": 12 | ||
"Patch": 13 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 154, | ||
"Patch": 12 | ||
"Patch": 13 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 3, | ||
"Minor": 154, | ||
"Patch": 12 | ||
"Patch": 13 | ||
}, | ||
"preview": true, | ||
"demands": [ | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 3, | ||
"Minor": 154, | ||
"Patch": 12 | ||
"Patch": 13 | ||
}, | ||
"preview": true, | ||
"demands": [ | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 153, | ||
"Patch": 1 | ||
"Patch": 2 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 153, | ||
"Patch": 1 | ||
"Patch": 2 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
Trace-VstsEnteringInvocation $MyInvocation | ||
Import-VstsLocStrings "$PSScriptRoot\Task.json" | ||
|
||
# Get inputs. | ||
$scriptType = Get-VstsInput -Name ScriptType -Require | ||
$scriptPath = Get-VstsInput -Name ScriptPath | ||
$scriptInline = Get-VstsInput -Name Inline | ||
$scriptArguments = Get-VstsInput -Name ScriptArguments | ||
$__vsts_input_errorActionPreference = Get-VstsInput -Name errorActionPreference | ||
$__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError | ||
$targetAzurePs = Get-VstsInput -Name TargetAzurePs | ||
$customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs | ||
$input_pwsh = Get-VstsInput -Name pwsh -AsBool | ||
$input_workingDirectory = Get-VstsInput -Name workingDirectory -Require | ||
|
||
# Validate the script path and args do not contains new-lines. Otherwise, it will | ||
# break invoking the script via Invoke-Expression. | ||
if ($scriptType -eq "FilePath") { | ||
if ($scriptPath -match '[\r\n]' -or [string]::IsNullOrWhitespace($scriptPath)) { | ||
throw (Get-VstsLocString -Key InvalidScriptPath0 -ArgumentList $scriptPath) | ||
} | ||
} | ||
|
||
if ($scriptArguments -match '[\r\n]') { | ||
throw (Get-VstsLocString -Key InvalidScriptArguments0 -ArgumentList $scriptArguments) | ||
} | ||
|
||
# string constants | ||
$otherVersion = "OtherVersion" | ||
$latestVersion = "LatestVersion" | ||
|
||
if ($targetAzurePs -eq $otherVersion) { | ||
if ($customTargetAzurePs -eq $null) { | ||
throw (Get-VstsLocString -Key InvalidAzurePsVersion $customTargetAzurePs) | ||
} else { | ||
$targetAzurePs = $customTargetAzurePs.Trim() | ||
} | ||
} | ||
|
||
$pattern = "^[0-9]+\.[0-9]+\.[0-9]+$" | ||
$regex = New-Object -TypeName System.Text.RegularExpressions.Regex -ArgumentList $pattern | ||
|
||
if ($targetAzurePs -eq $latestVersion) { | ||
$targetAzurePs = "" | ||
} elseif (-not($regex.IsMatch($targetAzurePs))) { | ||
throw (Get-VstsLocString -Key InvalidAzurePsVersion -ArgumentList $targetAzurePs) | ||
} | ||
|
||
. "$PSScriptRoot\Utility.ps1" | ||
|
||
$serviceName = Get-VstsInput -Name ConnectedServiceNameARM -Require | ||
$endpointObject = Get-VstsEndpoint -Name $serviceName -Require | ||
$endpoint = ConvertTo-Json $endpointObject | ||
|
||
try | ||
{ | ||
# Generate the script contents. | ||
Write-Host (Get-VstsLocString -Key 'GeneratingScript') | ||
$contents = @() | ||
$contents += "`$ErrorActionPreference = '$__vsts_input_errorActionPreference'" | ||
if ($env:system_debug -eq "true") { | ||
$contents += "`$VerbosePreference = 'continue'" | ||
} | ||
|
||
$CoreAzArgument = $null; | ||
if ($targetAzurePs) { | ||
$CoreAzArgument = "-endpoint '$endpoint' -targetAzurePs $targetAzurePs" | ||
} else { | ||
$CoreAzArgument = "-endpoint '$endpoint'" | ||
} | ||
$contents += ". $PSScriptRoot\CoreAz.ps1 $CoreAzArgument" | ||
|
||
if ($scriptType -eq "InlineScript") { | ||
$contents += "$scriptInline".Replace("`r`n", "`n").Replace("`n", "`r`n") | ||
} else { | ||
$contents += ". '$("$scriptPath".Replace("'", "''"))' $scriptArguments".Trim() | ||
} | ||
|
||
# Write the script to disk. | ||
$__vstsAzPSScriptPath = [System.IO.Path]::Combine($env:Agent_TempDirectory, ([guid]::NewGuid().ToString() + ".ps1")); | ||
$joinedContents = [System.String]::Join( | ||
([System.Environment]::NewLine), | ||
$contents) | ||
$null = [System.IO.File]::WriteAllText( | ||
$__vstsAzPSScriptPath, | ||
$joinedContents, | ||
([System.Text.Encoding]::UTF8)) | ||
|
||
# Prepare the external command values. | ||
# | ||
# Note, use "-Command" instead of "-File". On PowerShell V5, V4 and V3 when using "-File", terminating | ||
# errors do not cause a non-zero exit code. | ||
if ($input_pwsh) { | ||
$powershellPath = Get-Command -Name pwsh.exe -CommandType Application | Select-Object -First 1 -ExpandProperty Path | ||
} else { | ||
$powershellPath = Get-Command -Name powershell.exe -CommandType Application | Select-Object -First 1 -ExpandProperty Path | ||
} | ||
Assert-VstsPath -LiteralPath $powershellPath -PathType 'Leaf' | ||
$arguments = "-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command `". '$($__vstsAzPSScriptPath.Replace("'", "''"))'`"" | ||
$splat = @{ | ||
'FileName' = $powershellPath | ||
'Arguments' = $arguments | ||
'WorkingDirectory' = $input_workingDirectory | ||
} | ||
|
||
# Switch to "Continue". | ||
$global:ErrorActionPreference = 'Continue' | ||
$failed = $false | ||
|
||
# Run the script. | ||
Write-Host '========================== Starting Command Output ===========================' | ||
if (!$__vsts_input_failOnStandardError) { | ||
Invoke-VstsTool @splat | ||
} | ||
else { | ||
$inError = $false | ||
$errorLines = New-Object System.Text.StringBuilder | ||
Invoke-VstsTool @splat 2>&1 | | ||
ForEach-Object { | ||
if ($_ -is [System.Management.Automation.ErrorRecord]) { | ||
# Buffer the error lines. | ||
$failed = $true | ||
$inError = $true | ||
$null = $errorLines.AppendLine("$($_.Exception.Message)") | ||
|
||
# Write to verbose to mitigate if the process hangs. | ||
Write-Verbose "STDERR: $($_.Exception.Message)" | ||
} else { | ||
# Flush the error buffer. | ||
if ($inError) { | ||
$inError = $false | ||
$message = $errorLines.ToString().Trim() | ||
$null = $errorLines.Clear() | ||
if ($message) { | ||
Write-VstsTaskError -Message $message | ||
} | ||
} | ||
|
||
Write-Host "$_" | ||
} | ||
} | ||
|
||
# Flush the error buffer one last time. | ||
if ($inError) { | ||
$inError = $false | ||
$message = $errorLines.ToString().Trim() | ||
$null = $errorLines.Clear() | ||
if ($message) { | ||
Write-VstsTaskError -Message $message | ||
} | ||
} | ||
} | ||
|
||
# Fail if any errors. | ||
if ($failed) { | ||
Write-VstsSetResult -Result 'Failed' -Message "Error detected" -DoNotThrow | ||
} | ||
} | ||
finally { | ||
if ($__vstsAzPSInlineScriptPath -and (Test-Path -LiteralPath $__vstsAzPSInlineScriptPath) ) { | ||
Remove-Item -LiteralPath $__vstsAzPSInlineScriptPath -ErrorAction 'SilentlyContinue' | ||
} | ||
|
||
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ | ||
Remove-EndpointSecrets | ||
Disconnect-AzureAndClearContext -ErrorAction SilentlyContinue | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[String] [Parameter(Mandatory = $true)] | ||
$endpoint, | ||
|
||
[String] [Parameter(Mandatory = $false)] | ||
$targetAzurePs | ||
) | ||
|
||
Import-Module "$PSScriptRoot\ps_modules\VstsTaskSdk" -ArgumentList @{ NonInteractive = $true } | ||
Import-VstsLocStrings -LiteralPath "$PSScriptRoot\task.json" | ||
|
||
# Update PSModulePath for hosted agent | ||
. "$PSScriptRoot\Utility.ps1" | ||
CleanUp-PSModulePathForHostedAgent | ||
Update-PSModulePathForHostedAgent -targetAzurePs $targetAzurePs | ||
|
||
$endpointObject = ConvertFrom-Json $endpoint | ||
Import-Module "$PSScriptRoot\ps_modules\VstsAzureHelpers_" | ||
Initialize-AzModule -Endpoint $endpointObject -azVersion $targetAzurePs |
Oops, something went wrong.