How to debug Push-AppveyorArtifact when it fails - appveyor

As part of my CI running on AppVeyor I'm uploading a log from the installer using Push-AppveyorArtifact. While most of the time it works perfectly for a single PR the upload fails with the following output:
Push-AppveyorArtifactInternal : Error uploading artifact to the storage: One or more errors occurred.
At C:\Program Files\AppVeyor\BuildAgent\Modules\build-worker-api\build-worker- api.psm1:209 char:2
+ Push-AppveyorArtifactInternal -FullPath $fullPath -FileName $File ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Push-AppveyorArtifactInternal], Exception
+ FullyQualifiedErrorId : System.Exception,Appveyor.BuildAgent.Api.Utils.PushAppveyorArtifactInternalCmdlet
Command executed with exception: Error uploading artifact to the storage: One or more errors occurred.
Given this output is not very informative I am at a loss and have no idea how this can be debugged further. List of things I've tried:
Contacted AppVeyort support - no reply for over a month
Made sure that the file I am trying to upload exists and is not empty
Since as part of the problematic pull request the process which creates this file fails to exit properly I've tried killing it manually, confirmed that it is no longer active and retied the upload - same error.
Tried increasing the verbosity of Push-AppveyorArtifact by providing -Verbose -Debug which appears to be the highest verbosity level possible but no more info shows up.
It looks like the following sequence causes the upload to fail:
The process which creates a log file which fails to upload later on is started and then we're waiting for it to finish with wait-process for 3 minutes
If it finishes in the specified time the log file created it creates is uploaded successfully
Since we want to know if the process exited or not we need to specify -ErrorAction Stop for the wait-process invocation.
If wait-process raises an exception i.e. process is still running the Push-AppveyorArtifact fails with the error shown above

Related

PowerShell Import-GPO: Operation not valid

Afternoon everyone. I'm running into an issue I'm not sure how to handle. I'm working on a script for work to deploy a Domain Controller using PSremoting. It all works well in fine until I get to where I'm importing some GPOs from backups.
*All the commands are run under invoke-command
I run the command Import-GPO -BackUpName $GPO -TargetName $GPO -Path $GPOPath -MigrationTable $MigTable -CreateIfNeeded
When I run this, I get an error on the host:
Operation is not valid due to the current state of the object.
+ CategoryInfo : NotSpecified: (:) [Import-GPO], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.GroupPolicy.Commands.ImportGpoCommand
+ PSComputerName : v204-DC1
I can't seem to find anything that says what this means. When I check for the GPOs on the DC, they all show up and seem to be linked properly. I am curious what this error is, or if I should just append -ErrorAction SilentlyContinue to the end of my code.
Ended up being an issue with my migration table. I rolled back to an earlier one and ended up being good to go

Exception calling "ExtractToFile" when unzipping

I've tried a couple of solutions to unzip a file containing the path:
\Content\F_C\Jenkinsworkspace\workspace\BUILD.PROJECT.GENERICS\PROJECT_Generics\PROJECT.Generics\PROJECT.Generic\obj\Debug\Package\PackageTmp
but I get the error:
Exception calling "ExtractToFile" with "3" argument(s): "Could not find a part of the path
Expand-Archive -LiteralPath F:\Jenkinsworkspace\workspace\BUILD.GENERIC.GENERICS\GENERIC.Generic.zip -DestinationPath F:\Jenkinsworkspace\workspace\BUILD.GENERIC.GENERICS\UNZIPED2 -Force
Exception calling "ExtractToFile" with "3" argument(s): "Could not find a part of
the path 'F:\Jenkinsworkspace\workspace\BUILD.GENERIC.GENERICS\UNZIPED2\Content\
F_C\Jenkinsworkspace\workspace\BUILD.GENERIC.GENERICS\GENERIC_Generics
\GENERIC.Generics\GENERIC.Generic\obj\Debug\Package\PackageTmp\modules\
_protected\EPiServer.GoogleAnalytics\EPiServer.GoogleAnalytics.zip'."
At
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:1033 char:25
+ ... [System.IO.Compression.ZipFileExtensions]::ExtractToFile( ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DirectoryNotFoundException
I'm guessing it's because I have a zip within a zip.
In our case, though the path was short, we were getting the same error.
Sharing our solution which might be useful for someone.
We were trying to unzip the package on our application server through powershell script. Basically powershell script runs on our build server & remotely connect to our application server. It was then trying to unzip the package present on application server.
The above scenario was working fine for quite some time before it starts to throw the error during unzipping.
Solution:
We found the reason was anti virus policy, which was blocking the unzipping through remote powershell script.
Soved using this Blog :
https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/
changing the group policy solved the problem

VSTS release only logs the 1st line of a Powershell exception as an error. How can I log the full exception details without enabling debug?

If I run this code (containing a null reference) in Powershell ISE
$result = $nonExistentString.Substring(0,4)
An exception is thrown and the following is output to the console
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $result = $nonExistentString.Substring(0,4)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
However, if I run the same code in a VSTS release as a powershell inline script, the release log will only output the following :
2017-11-30T13:23:26.9471504Z ##[error]You cannot call a method on a null-valued expression.
This isn't enough detail to facilitate problem resolution in more complex scripts. I know I can run the scripts in debug mode and the full exception record is logged as debug entries, but this would mean we would need to run all scripts in debug at all times in order to get full exception details when they occur. Does anyone know if it possible to configure VSTS to log full exception details without having to enable debug?

Why am I getting an error when trying to remove a Microsoft.Insights/components resource?

I am trying to execute a PowerShell script that will sequentially remove Azure Resources from a resource group using a .ps1 file, and have isolated an error I am getting to whenever I try to remove the Microsoft.Insights/components resource using the command:
Remove-AzureRmResource -ResourceId "/subscriptions/e41d3122-bbd8-48dc-a212-0337139671cc/resourceGroups/TestRG/providers/Microsoft.Insights/components/WA-Stag-API-EMEA-zgqmgcwnigknu"
The error I'm getting after running this once is as follows:
Remove-AzureRmResource : {"code":"Message: {\"Errors\":[\"One of the
specified pre-condition is not met\"]}","message":"Message:
{\"Errors\":[\"One of the specified pre-condition is not
met\"]}\r\nActivityId: 845b19fa-b6b4-4952-9b62-75bfc6e98646, Request
URI:
/apps/1921ec42-1c88-4fdd-8d6c-78646cba4b15/services/a32b484a-6ee1-4ad7-ab43-4e9
d57bb0b81/partitions/fab8c193-3ec3-45e8-b7a6-0e21d1e071da/replicas/131441657816991616p","innererror":{"diagnosticcontext":"597ea546-7625-474d-b27f-560a1140a652","time":"2017-
07-18T19:41:25.3734216Z"}} At line:1 char:1
+ Remove-AzureRmResource -ResourceId "/subscriptions/e41d3122-bbd8-48dc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzureRmResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : Conflict,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet
From what I can tell, there seems to be some kind of "pre-condition" that needs to be met before you can delete it... but the weirdest part is that if I execute the same command again, I don't get an error and the resource is successfully deleted...
Is there any reason why this would fail once, but then succeed in being deleted after executing again?
This is because the Insights is used by your Web APP. Please refer to this link. When you enable client side monitoring, you will get the error log. I test in my lab, I get the same result with you.
If you want to avoid this error log. Please refer to the following steps:
1.Delete APPINSIGHTS_JAVASCRIPT_ENABLED key.
2.Restart your app.
3.Delete Insights.

Random errors while doing Enter-PSSession in powershell

I have setup lots of Powershell scripts on my WIndows 2008 R2 server. The scripts do lots of processing (data crunching, executing SQLCMD.exe, bcp.exe etc). All of these scripts work without issues.
I am trying to call and execute the scripts from a remote laptop (within the same network) using the following command:
Enter-PSSession -ComputerName sun -ConfigurationName myprofile
The "myprofile" currently has just one function that will change directory to c:
This allows me to execute the scripts from my local laptop, however, they "run" on the server. That is my understanding.
However, I have not seen any scripts execute fully. At random intervals, the scripts fail with the below error messages... Once again, I have never seen these errors when I am trying to run the scripts on the server itself.
Any inputs on how to "fix" these errors? Any settings that I need to do on the "client" in terms of memory allocation?
a.
Processing data for a remote command failed with the following error message: Not enough storage is available to complete this operation. For more information, see the about_Remote_Troubleshooting Help topic.
b.
Get-Content : Exception of type 'System.OutOfMemoryException' was thrown.
At E:\automation\mssql-upload.ps1:144 char:14
+ (get-content <<<< $PipeFile -ReadCount 1000) | set-content $FinalFile
+ CategoryInfo : InvalidOperation: (:) [Get-Content], OutOfMemoryException
+ FullyQualifiedErrorId : ProviderContentReadError,Microsoft.PowerShell.Commands.GetContentCommand
c.
[Microsoft] [ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV
d.
Processing data for a remote command failed with the following error message: The WSMan provider host process did not return a proper response. A provider in the host process may have behaved improperly. For more information, see the about_Remote_Troubleshooting Help topic.
It is likely your remote session is bumping up against the WS-Man quota MaxMemoryPerShellMB. You can see the current value by executing this command on the remote machine:
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB
You can set a new value like so:
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 512 -Force
This sets the value at 512MB. Set it to a value that works for your application.