Jenkins Build successful even after PS script failed to execute - powershell

I am executing Jenkins Job which Builds my .csproj file and execute few PS scripts.
Issue is I get a successful email even if my PS script fails,How should I tell my Jenkins Job to trigger me an email also if PS script is failing.
Error Logs-
Copy-Item : The process cannot access the file
'\\10.0.1.190\d$\Build\RPC\abcde.RPC.AirSearch\Common.Logging.Core.dll' because it is being used by another process.
At C:\Users\Administrator\AppData\Local\Temp\hudson9059014122834846757.ps1:3 char:1
+ Copy-Item "C:\AirSearchBnd\src\abcde.Air.Search.RPC.Host\bin\Release\*" "\\$en ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], IOException
+ FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand
[AirSearchBnd] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\ADMINI~1\AppData\Local\Temp\hudson9149103993066004448.ps1'"
[SC] CreateService SUCCESS
SERVICE_NAME: AirSearchWindowsService
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 13784
FLAGS :
> C:\Program Files (x86)\Git\bin\git.exe tag -l RPCBUILD_6 # timeout=10
> C:\Program Files (x86)\Git\bin\git.exe tag -a -f -m Jenkins Git plugin tagging with RPCBUILD_6 RPCBUILD_6 # timeout=10
Pushing tag RPCBUILD_6 to repo Dev
> C:\Program Files (x86)\Git\bin\git.exe --version # timeout=10
using GIT_ASKPASS to set credentials
> C:\Program Files (x86)\Git\bin\git.exe push https://github.com/abcdeHoldings/abcde.Services.Air.Search.git RPCBUILD_6
Email was triggered for: Always
Sending email for trigger: Always
Request made to compress build log
Sending email to: abcde#software.com abcde#software.com abcde#software.com abcde#software.com
Finished: SUCCESS

The easiest way is to configure Jenkins to send e-mails on failed builds and in the Powershell step add the following at the end:
if ($error) { exit 1 }
The problem with Jenkins Powershell plugin is that it doesn't honor the errors that happen in Powershell, only the exit code of the shell itself, this will force build to fail and trigger the email.

There is an option of "Attaching Build Log". You can read the build log to see, if the ps script has failed.

Related

vscode SSH connect failed using SSH-remote extension but success by terminal

I'm trying to setup a ssh server using my win10 PC. After following steps to setup the server, it is now can be connected via terminal from by laptop(win11).
However, if I use vscode extension Remote - SSH with connecting config :
Host 192.168.0.183
HostName 192.168.0.183
User User
Port 22
I always encounter Could not establish connection :
[23:49:42.494] Got password response
[23:49:42.494] "install" wrote data to terminal: "**********"
[23:49:42.521] >
[23:49:42.815] > powershell : �L�k���� 'powershell' ���J�O�_�� Cmdlet�B��ơB���O�ɩΥi����{�����W�١C���ˬd�W�٫��r�O�_���T�A�p�G�]�t
[23:49:42.826] > ��|���ܡA�нT�{��|�O�_���T�A�M��A�դ#���C
��� �u��:1 �r��:1
+ powershell
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (powershell:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
[23:49:44.124] "install" terminal command done
[23:49:44.125] Install terminal quit with output:
[23:49:44.126] Received install output:
[23:49:44.129] Resolver error: Error:
at g.Create (c:\Users\lspss\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:583926)
at c:\Users\lspss\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:581767
at t.handleInstallOutput (c:\Users\lspss\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:582462)
at t.tryInstall (c:\Users\lspss\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:680469)
at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
at async c:\Users\lspss\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:642848
at async t.withShowDetailsEvent (c:\Users\lspss\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:646166)
at async t.resolve (c:\Users\lspss\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:643898)
at async c:\Users\lspss\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:723024
[23:49:44.138] -----
Then I tried to use the laptop setting up as server and PC otherwise. It connect successfully with following output log :
[23:56:27.929] Got password response
[23:56:27.929] "install" wrote data to terminal: "************"
[23:56:27.951] >
[23:56:28.645] > Windows PowerShell
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> Install the latest PowerShell for new features and improvements! https://aka.ms/
> PSWindowsPS C:\Users\lspss>
> PS C:\Users\lspss> $uuid="d68ebbafd913"
> PS C:\Users\lspss> "${uuid}: running"
> d68ebbafd913: running
> PS C:\Users\lspss> "d68ebbafd913: pauseLog"
> d68ebbafd913: pauseLog
In comparison, the failed one have some random code I do not understand follow the powershell, while the other success after Windows Powershell.
I have tried to reinstall the ssh-server on my PC, and also tried using other laptop as client, which all failed.

How do I pipe input to a command using powershell in a Dockerfile?

I'm trying to write a Dockerfile to build a windows image containing the android sdk.
During the installation of the sdk, the sdkmanager requires you to enter 'y' several times to accept licenses before continuing. I've been able to automate this in a normal powershell outside docker with the following line:
"y`n" * 8 | & '.\bin\sdkmanager.bat' --licenses
However, when I try to put this in the Dockerfile, it doesn't work. The sdkmanager ignores the input and just exits immediately at the first prompt.
Dockerfile (the triple quotes seem necessary to prevent them being stripped):
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2016
RUN iwr -UseBasicParsing https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip -OutFile sdk-tools.zip
RUN Expand-Archive sdk-tools.zip 'C:\Program Files (x86)\Android\android-sdk'
RUN """y`n""" * 8 | & 'C:\Program Files (x86)\Android\android-sdk\tools\bin\sdkmanager.bat' --licenses
RUN & 'C:\Program Files (x86)\Android\android-sdk\tools\bin\sdkmanager.bat' tools platform-tools
Output:
Step 7/14 : RUN iwr -UseBasicParsing https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip -OutFile sdk-tools.zip
---> Using cache
---> dfb0b47e99b8
Step 8/14 : RUN Expand-Archive sdk-tools.zip 'C:\Program Files (x86)\Android\android-sdk'
---> Using cache
---> a87ab84f86d0
Step 9/14 : RUN """y`n""" | & 'C:\Program Files (x86)\Android\android-sdk\tools\bin\sdkmanager.bat' --licenses
---> Running in b5caf5584ba3
Warning: File C:\Users\ContainerAdministrator\.android\repositories.cfg could not be loaded.
7 of 7 SDK package licenses not accepted. 100% Computing updates...
Review licenses that have not been accepted (y/N)?
Removing intermediate container b5caf5584ba3
---> 2d88d3c72d9a
Step 10/14 : RUN & 'C:\Program Files (x86)\Android\android-sdk\tools\bin\sdkmanager.bat' tools platform-tools
---> Running in 27e8f5e804e9
I assume this is maybe a docker build limitation where it doesn't wait for user input. Is there any way around this?

Can't run stock SF Container out of the box on local cluster

I created a stock out of the box VS2019 Azure Service Fabric Container app. It and every other Service Fabric app won't run on the local cluster. I get this:
1>------ Build started: Project: ServiceFabricContainer, Configuration: Debug x64 ------
2>------ Publish started: Project: ServiceFabricContainer, Configuration: Debug x64 ------
2>Started executing script 'GetApplicationExistence'.
2>Finished executing script 'GetApplicationExistence'.
2>Time elapsed: 00:00:00.5863836
-------- Package started: Project: ServiceFabricContainer, Configuration: Debug x64 ------
ServiceFabricContainer -> C:\dev\ServiceFabricContainer\pkg\Debug
-------- Package: Project: ServiceFabricContainer succeeded, Time elapsed: 00:00:00.2741254 --------
2>Started executing script 'Deploy-FabricApplication.ps1'.
2>powershell -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command ". 'C:\dev\ServiceFabricContainer\Scripts\Deploy-FabricApplication.ps1' -ApplicationPackagePath 'C:\dev\ServiceFabricContainer\pkg\Debug' -PublishProfileFile 'C:\dev\ServiceFabricContainer\PublishProfiles\Local.1Node.xml' -DeployOnly:$false -ApplicationParameter:#{} -UnregisterUnusedApplicationVersionsAfterUpgrade $false -OverrideUpgradeBehavior 'None' -OverwriteBehavior 'SameAppTypeAndVersion' -SkipPackageValidation:$false -ErrorAction Stop"
2>Copying application to image store...
2>Upload to Image Store succeeded
2>Registering application type...
2>Register application type started. Use Get-ServiceFabricApplicationType to query for status.
2>Running Image Builder process ...
2>Application package is registered.
2>Removing application package from image store...
2>Remove application package succeeded
2>Creating application...
2>New-ServiceFabricApplication : Repository Credentials for Account Name:sgentile cannot have a blank password if you
2>have PasswordEncrypted set to True or Type set to Encrypted/SecretsStoreRef.
2>At C:\Program Files\Microsoft SDKs\Service
2>Fabric\Tools\PSModule\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:358 char:9
2>+ New-ServiceFabricApplication -ApplicationName $ApplicationNam ...
2>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2> + CategoryInfo : InvalidOperation: (Microsoft.Servi...usterConnection:ClusterConnection) [New-ServiceFabr
2> icApplication], FabricException
2> + FullyQualifiedErrorId : CreateApplicationInstanceErrorId,Microsoft.ServiceFabric.Powershell.NewApplication
2>
2>Finished executing script 'Deploy-FabricApplication.ps1'.
2>Time elapsed: 00:00:09.7611521
2>The PowerShell script failed to execute.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
Help please!
The answer is right in the error information. I just needed to have a non blank password. It works now.

Windows Machine File Copy won't work without shared folder

I am using VSTS Release Management. The first step is to do a "Windows Machine File Copy". The settings are below. This fails when doing the robocopy with an error message of "Access Denied". The file path shown in the settings below gets translated to \\machine\e$\xxxx\TargetFolder. Why am I getting access denied? I don't get this message if I create a shared folder on the target folder and change the destination folder to: \\machine\TargetFolder. The Admin user is a local admin on the machine.
My question is why do I need to setup a shared folder in order to get this to work. Why can't it use the admin share (i.e. \\machine\e$\xxxx\TargetFolder)
Here is the log. The source and destination servers are both Win 2012R2 servers. UAC is turned off on the destination server. I have tried /B and /ZB as arguments and that didn't work.
2017-02-20T12:21:10.4545267Z Downloading artifact
2017-02-20T12:21:11.4375965Z Cleaning artifacts directory: C:\VSTS_agent\ReleaseManagementVSTS\r1\a
2017-02-20T12:21:11.6306012Z Cleaned artifacts directory: C:\VSTS_agent\ReleaseManagementVSTS\r1\a
2017-02-20T12:21:11.6396014Z Starting artifacts download...
2017-02-20T12:21:11.6426015Z Downloading linked artifact Release Build of type Build...
2017-02-20T12:21:11.6486018Z Ensuring artifact folder C:\VSTS_agent\ReleaseManagementVSTS\r1\a\Release Build exists and is clean.
2017-02-20T12:21:11.6856039Z Preparing to get the list of available artifacts from build
2017-02-20T12:21:12.0926382Z Preparing to download artifact: release
2017-02-20T12:21:12.1066374Z Artifact Type: ServerDrop
2017-02-20T12:21:12.5536635Z Caching items under 'release' in the file container...
2017-02-20T12:21:12.7186787Z Caching complete. (165 ms)
2017-02-20T12:21:17.8480056Z Download complete.
2017-02-20T12:21:17.8500047Z 51 placed file(s): 51 downloaded, 0 empty
2017-02-20T12:21:17.8500047Z 11 MB downloaded at 2188 KB/sec. Download time: 00:00:05.0976254. Parallel download limit: 4.
2017-02-20T12:21:17.8510054Z Downloaded linked artifact Release Build
2017-02-20T12:21:17.8510054Z Finished artifacts download
2017-02-20T12:21:17.8610039Z ##[section]Finishing: Download Artifacts
2017-02-20T12:21:17.8690051Z ##[section]Starting: Copy files from $(System.DefaultWorkingDirectory)/Release Build/release
2017-02-20T12:21:17.9680113Z ==============================================================================
2017-02-20T12:21:17.9680113Z Task : Windows Machine File Copy
2017-02-20T12:21:17.9680113Z Description : Copy files to remote machine(s)
2017-02-20T12:21:17.9690126Z Version : 1.0.39
2017-02-20T12:21:17.9690126Z Author : Microsoft Corporation
2017-02-20T12:21:17.9690126Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=627415)
2017-02-20T12:21:17.9690126Z ==============================================================================
2017-02-20T12:21:18.0380182Z Preparing task execution handler.
2017-02-20T12:21:19.8101219Z Executing the powershell script: C:\VSTS_agent\ReleaseManagementVSTS\_tasks\WindowsMachineFileCopy_xxxx\1.0.39\WindowsMachineFileCopy.ps1
2017-02-20T12:21:24.0233892Z Copy started for - 'machine'
2017-02-20T12:21:28.8116953Z
2017-02-20T12:21:28.8116953Z -------------------------------------------------------------------------------
2017-02-20T12:21:28.8116953Z ROBOCOPY :: Robust File Copy for Windows
2017-02-20T12:21:28.8116953Z -------------------------------------------------------------------------------
2017-02-20T12:21:28.8116953Z
2017-02-20T12:21:28.8146952Z Started : Monday, February 20, 2017 7:21:28 AM
2017-02-20T12:21:28.8156949Z 2017/02/20 07:21:28 ERROR 5 (0x00000005) Getting File System Type of Destination \\machine\E$\xxx\TargetFolder\
2017-02-20T12:21:28.8156949Z Access is denied.
2017-02-20T12:21:28.8156949Z
2017-02-20T12:21:28.8156949Z
2017-02-20T12:21:28.8156949Z Source : C:\VSTS_agent\ReleaseManagementVSTS\r1\a\Release Build\release\
2017-02-20T12:21:28.8167052Z Dest - \\machine\E$\xxx\TargetFolder\
2017-02-20T12:21:28.8167052Z
2017-02-20T12:21:28.8167052Z Files : *.*
2017-02-20T12:21:28.8167052Z
2017-02-20T12:21:28.8167052Z Options : *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30
2017-02-20T12:21:28.8167052Z
2017-02-20T12:21:28.8167052Z ------------------------------------------------------------------------------
2017-02-20T12:21:28.8186939Z
2017-02-20T12:21:28.8196951Z 2017/02/20 07:21:28 ERROR 5 (0x00000005) Creating Destination Directory \\machine\E$\xxx\TargetFolder\
2017-02-20T12:21:28.8196951Z Access is denied.
2017-02-20T12:21:28.8196951Z
2017-02-20T12:21:28.8977003Z \\machine was deleted successfully.
2017-02-20T12:21:28.8977003Z
2017-02-20T12:21:28.9177039Z ##[error]System.Management.Automation.RuntimeException: Copying failed for resource : machine
2017-02-20T12:21:28.9177039Z Copying failed. Consult the robocopy logs for more details. ---> System.Management.Automation.RuntimeException: Copying failed for resource : machine
2017-02-20T12:21:28.9177039Z Copying failed. Consult the robocopy logs for more details.
2017-02-20T12:21:28.9177039Z --- End of inner exception stack trace ---
2017-02-20T12:21:28.9177039Z at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
2017-02-20T12:21:28.9177039Z at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
2017-02-20T12:21:28.9177039Z at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
2017-02-20T12:21:28.9177039Z at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2017-02-20T12:21:28.9177039Z at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2017-02-20T12:21:28.9187021Z at Microsoft.TeamFoundation.DistributedTask.Handlers.LegacyVSTSPowerShellHost.VSTSPowerShellHost.Main(String[] args)
2017-02-20T12:21:28.9407042Z ##[error]LegacyVSTSPowerShellHost.exe completed with return code: -1.
2017-02-20T12:21:28.9427038Z ##[section]Finishing: Copy files from $(System.DefaultWorkingDirectory)/Release Build/release
2017-02-20T12:21:28.9507042Z ##[section]Finishing: Release
This issue was resolved by using an Active Directory account. This fixed the issue of not being able to Robocopy with the admin share. This worked on machines that the AD user had access, and for machines where the AD didn't have access but where a local admin windows account was setup with the same name as the AD account.

Running tests with tcm.exe results in Field not found: 'Microsoft.TeamFoundation.TestManagement.Common.WitCategoryRefName.SharedDataSet'

I'm trying to run an automated test case in Microsoft Test Manager from the command line with the following command:
TCM.exe run /create /title:"Nightly Run" /planid:5554 /suiteid:6582 /configid:97 /collection:XXX /teamproject:XXX /include /builddir:'C:\Source\'
This results in the following error:
.\TCM.exe : Field not found: 'Microsoft.TeamFoundation.TestManagement.Common.WitCategoryRefName.SharedDataSet'.
At C:\Users\XXXX\Desktop\RunTest.ps1:2 char:1
+ .\TCM.exe run /create /title:"Nightly Run" /planid:5554 /suiteid:6582 /configid: ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Field not found...SharedDataSet'.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
However, this error happens on a Windows Server 2012R2 machine with Visual Studio 2013.4 installed but not on my local dev machine (Windows 10 with VS2013.4).
I know that SharedDataSets are introduced in VS2013.4 but I don't know where this error is coming from since the command doesn't give this error on my local pc.
I've found the solution. Running the following commands on the Windows Server fixed the error:
ngen uninstall Microsoft.TeamFoundation.TestManagement.Client
ngen uninstall Microsoft.TeamFoundation.TestManagement.Common