Last active
January 24, 2020 08:51
-
-
Save mortenlerudjordet/7ee6ff5b3f6593217b6e35132675690f to your computer and use it in GitHub Desktop.
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
<# | |
.SYNOPSIS | |
Removes git extraheader for AzD project from pipeline after terraform has feteched modules from AzD repo | |
.DESCRIPTION | |
.PARAMETER AzDteamAccountURL | |
Azure DevOps account url | |
https://dev.azure.com/AccountName | |
.PARAMETER Verbose | |
If set will print git system config content to log | |
.NOTES | |
AUTHOR: Morten Lerudjordet | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNullorEmpty()] | |
[string]$AzDaccountURL | |
) | |
try { | |
Write-Host -Object "Task started at time: $(get-Date -format r).`nRunning PS version: $($PSVersionTable.PSVersion)`nOn agent: $($env:computername)" | |
$GitTempConfigFileName = ".gitconfig.$($env:Release_ReleaseId)" | |
if ($VerbosePreference -ne 'SilentlyContinue') { | |
Write-Host -Object "Getting list of git global config from agent" | |
$GitCommand = "& `"$env:ProgramFiles\Git\cmd\git.exe`" config --global --list" | |
$GitCommandResult = Invoke-Expression -Command $GitCommand -ErrorAction SilentlyContinue -ErrorVariable oErr | |
if ($oErr) { | |
Write-Error -Message "Failed to run git command to list global config: $AzDaccountURL.`nError: $($oErr.Message)" -ErrorAction Stop | |
} | |
if ($GitCommandResult) { | |
Write-Host -Object "List from global config:" | |
Write-Host -Object $GitCommandResult | |
} | |
} | |
Write-Host -Object "Removing git extraheader from agent config for $AzDaccountURL" | |
$GitCommand = "& `"$env:ProgramFiles\Git\cmd\git.exe`" config --global --unset include.path `"$GitTempConfigFileName`"" | |
$GitCommandResult = Invoke-Expression -Command $GitCommand -ErrorAction SilentlyContinue -ErrorVariable oErr | |
if ($oErr) { | |
Write-Error -Message "Failed to run git command for clearing extraheader.`nError: $($oErr.Message)" -ErrorAction Stop | |
} | |
if ($GitCommandResult) { | |
Write-Host -Object "Output from git command:" | |
Write-Host -Object $GitCommandResult | |
Write-Error -Message "Unexpected output from clearing extraheader for $AzDaccountURL" -ErrorAction Stop | |
} | |
else { | |
Write-Host -Object "Successfully removed temp git config file from global config" | |
} | |
if ($VerbosePreference -ne 'SilentlyContinue') { | |
Write-Host -Object "Getting list of git global config from agent" | |
$GitCommand = "& `"$env:ProgramFiles\Git\cmd\git.exe`" config --global --list" | |
$GitCommandResult = Invoke-Expression -Command $GitCommand -ErrorAction SilentlyContinue -ErrorVariable oErr | |
if ($oErr) { | |
Write-Error -Message "Failed to run git command to list global config: $AzDaccountURL.`nError: $($oErr.Message)" -ErrorAction Stop | |
} | |
if ($GitCommandResult) { | |
Write-Host -Object "List from global config:" | |
Write-Host -Object $GitCommandResult | |
} | |
} | |
} | |
catch { | |
if ($_.Exception.Message) { | |
Write-Error -Message "$($_.Exception.Message)" -ErrorAction Continue | |
Write-Host -Object "##[error]$($_.Exception.Message)" | |
} | |
else { | |
Write-Error -Message "$($_.Exception)" -ErrorAction Continue | |
Write-Host -Object "##[error]$($_.Exception)" | |
} | |
} | |
finally { | |
Write-Host -Object "Task ended at time: $(get-Date -format r)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment