06-21-2019 07:46 AM
Hi Team,
I'm creating a batch file for automating tests and builds (using Jenkins) but I'm struggling to work out how to to do a basic IF statement if the build fails.
Basically, If a build fails, I want to EXIT <error code>, ELSE carry on with the rest of the script
If I send a command like this:
LabVIEWCLI -OperationName ExecuteBuildSpec -ProjectPath "<path>" -TargetName "My Computer" -BuildSpecName "exe"
and it fails, it will return something like this:
Operation output: Error Code : 7 Error Message : Invoke Node in GetTargetBuildSpecs.vi->NI_App_Builder_API.lvlib:Build (path).vi->ExecuteBuildSpec.lvclass:RunOperation.vi:5910001->CoreOperation.lvclass:CallRunOperation.vi:4230002->ExecuteRunOperation.vi:5250001->ExecuteOperation.vi:6900002->ExecuteOperation.vi.ProxyCaller <APPEND> Method Name: <b>Project:Open</b> An error occurred while running the ExecuteBuildSpec operation. ExecuteBuildSpec operation failed.
Or if it is successful it will return this:
Operation output: Generated files are: C:\Users\Software\Desktop\testcode\builds\exe\Application.exe C:\Users\Software\Desktop\testcode\builds\exe\Application.aliases C:\Users\Software\Desktop\testcode\builds\exe\Application.ini ExecuteBuildSpec operation succeeded.
Can someone let me know, how based on the return data I can use simple if statements to either 'stop and return an error code' or continue with the rest of the script?
Solved! Go to Solution.
06-21-2019 09:58 AM
Are you able to get the response string back into LabVIEW through one of the SystemCommand subVI outputs?
06-21-2019 10:11 AM
Never used LabVIEWCLI. However, usually console programs return error information into the environmental variable %ERRORLEVEL%; there is plenty of tutorials and examples about this, see for example this link (picked almost a random). Check the statement 'IF ERRORLEVEL n' to react to errors. Statement 'GOTO label' will also help you to contnue processing elsewhere in the batch file.
06-24-2019 03:52 AM
Thank you pincpanter,
Your solution was simple and worked straight away.
For the benefit of others this is how I implemented the solution:
@echo on rem :: This section is to set batch file variables SET PROJECTNAME=<projectname>.lvproj SET EXEBUILDSPEC="<exename>" SET INSBUILDSPEC="<installername>" rem :: This is the main script LabVIEWCLI -OperationName ExecuteBuildSpec -ProjectPath "%cd%\%PROJECTNAME%" -TargetName "My Computer" -BuildSpecName %EXEBUILDSPEC% IF %errorlevel% NEQ 0 ( goto error ) LabVIEWCLI -OperationName ExecuteBuildSpec -ProjectPath "%cd%\%PROJECTNAME%" -TargetName "My Computer" -BuildSpecName %INSBUILDSPEC% IF %errorlevel% NEQ 0 ( goto error ) LabVIEWCLI -OperationName CloseLabVIEW IF %errorlevel% NEQ 0 ( goto error ) :error EXIT %errorlevel%
06-02-2020 01:52 PM
Just in case other people see it.
$? also returns a boolean value about whether it failed or succeeded.
Additionally, the return values and paths can be accessed like this:
$buildOutput = LabVIEWCLI -OperationName ExecuteBuildSpec -ProjectPath...
echo $buildOutput[6]
$buildOutput is an array where each item is a line from the output of the LabVIEWCLI command (note that this will prevent those lines from displaying in the console)
You can access the information in those lines as a standard array. For instance, $buildOutput[6] is the first line in the Operation Output and contains the file path for the executable.