Display build error in build status page (Jenkins) - linux

I have a freestyle jenkins project which basically just invokes a linux script which writes a long logfile.
If the script fails, then the last line of the logfile will be a human readable description, but I can't add any more build steps to parse it since it's already failed at this point.
Is there an easy way to basically do msg=$(tail -n1 logfile.log) and then display that $msg as a build description in the build status page?
It would make it much easier than having to click on the console output for each build and scroll to the bottom.
I have tried the Customized Build Message plugin which seems like it kind of works, except I can't export the logfile to access from an ENV variable. I also looked at the Console Log Parser, but it doesn't support just getting the last line.

Related

Linux: How to cat stdout of a process until the end, but stop and return a non-zero code if certain string appears?

We have a tool that runs tests, but does return an error code if they fail.
The tool runs the tests after starting logging in through SSH to a custom console (not bash) and issuing a command. All tests run at once within that invocation
The logging of the tests goes to a file.
The output of the tool is roughly:
test1 [ok]
test2 Some message based on the failure
...
To stop the build, we need to look for certain strings in the output.
The output appears as the tests run.
I could capture the whole output into a file and fail at the end. But it would save quite some time to fail once the first test fails.
Therefore, I would like something like tee, but it would also kill the execution if it finds that failure string. Or, at least, it should print the output as it comes, and return non-zero if a string is found.
Is this doable with the standard Linux toolkit?
The only solution I can think of is:
Start you build process and cat its output to an output file.
Start another script that monitors this file: a loop which iterates every X seconds in search for your, lets say, forbidden words in the file. As soon as they appear, kill the build process (you may need a way to identify your build process, such as a pid file or something like this) and clear the file.
You can even put this 2 processes in a single shellscript and make them both start and stop when needed.

How to validade if a Groovy file is with correct syntax without running it?

I'd like to run a shell script that would tell me if a Groovy file is syntactically correct without executing it. The code wouldn't be run, just validated.
I see that there are similar questions, but I would like a simple command line command. I thought there would be parameter for the compiler, but couldn't find it.
I didn't manage to get a direct answer. My problem was that I was making a Jenkins pipeline script and I'd like to verify it before commit and push. This was I would get simples errors in less time.
I've solved my problem using a VSCode Extension to validate the file before committing. No more typos in committed in my version control.

Cannot write to file when using task manager for python script

I have created a python script that given an input file, will run NMap on arguments from the input file. It then writes to an output file in csv format. My script works fine and as intended when I run from IDLE, but when my script runs from the task manager, it never overwrites the excel/csv file I tell my script to write to. The path I provide in the file:
ipResults = r'C:\Users\________\Documents\Results.csv'
I've left out the username for security concerns.
I've set the script to run when I log on. When I log on, I see the output/results in a taskeng.exe window with with a python symbol and rocketship. But when it finishes running, Results.csv does not get updated. As said previously, when running through IDLE, the script does overwrite Results.csv.
Currently I have set my file to both w+ changing it from w to see if that's the error but no such luck. I'm fine with the program overwriting my past results, in fact that's what I want, but when my script is ran through the task manager it does not overwrite the Results.csv file.
Simply checking the run with highest privilege box when setting the task up on task manager fixed my error, I am now able to write to my output file.

Python Terminal Calls Fail to Interact with Files

I am writing a program that handles some data on a server. Throughout the program, many files are made and sent as input into other programs. To do this, I usually make the command string, then run it like so:
cmd = "prog input_file1 input_file2 > outputfile"
os.system(cmd)
When I run the command, however, the programs being called report that they cannot open the files. If I run the python code on my local computer, it is fine. When I loaded it onto the server, it started to fail. I think this is related to issues with permissions, but am not sure how I can fix this. Many of the files, particularly the output files, are being created at run time. The input files have full permissions for all users. Any help or advice would be appreciated!
Cheers!
The python code you list is simple and correct, so the problem is likely not in the two lines of your example. Here are some related areas for you to check out.
Permissions
The user running the python script must have the appropriate permission (read, write, execute). I see from comments that you've already checked this.
What command are you running
If the command is literally typed into your source code like in the example, then you know what command is being run, but if you are generating any part of it (eg. the list of operands, the name of the output file, other parameters, etc), make sure there are no bugs in the portions of your code that generate the command. For example before the call to os.system(cmd) consider including a line like print("About to execute: " + cmd) so you can see exactly what will be run.
Directly invoke the command
If all the above looks good, try to execute the command directly at a terminal on your server. What output do you get then. It's possible that the problem is with the underlying command itself rather than your python code.

InstallShield Reponse File missing a response

I am trying to automate the install of a few setup files (.exe). I managed to get one working without any issue but am having difficulty with the second.
I created response files by using the following in command prompt:
MyProgram.exe -r
This generated a "setup.exe" file in C:\Windows as I would expect it to. Here is an example of what the file looks like in notepad:
[{PRODUCT_GUID}-DlgOrder]
Dlg0={PRODUCT_GUID}-SdWelcome-0
Count=5
Dlg1={PRODUCT_GUID}-SdLicense-0
Dlg2={PRODUCT_GUID}-SdAskDestPath-0
Dlg3={PRODUCT_GUID}-SdSelectFolder-0
Dlg4={PRODUCT_GUID}-SdStartCopy-0
[{PRODUCT_GUID}-SdWelcome-0]
Result=1
[{PRODUCT_GUID}-SdLicense-0]
Result=1
[{PRODUCT_GUID}-SdAskDestPath-0]
szDir=C:\Example\
Result=1
[{PRODUCT_GUID}-SdSelectFolder-0]
szFolder=Example\Folder
Result=1
[{PRODUCT_GUID}-SdStartCopy-0]
Result=1
I run the install with the setup.iss (response file) using the command:
program.exe /S /f1.\setup.iss
All response files seem to work except for one. The program opens a dialog asking me to select from a pair of radio buttons to select what language manual I want it to install. I want it to default to hit the "Next" button but there's obviously nothing recorded in the .iss file to do so.
What do I have to manually add to the .iss file in order to complete this prompt?
Why doesn't my recording put this in?
Additional information:
If I manually hit "Next" at this step, the program completes install as expected.
The program successfully installs when I install everything manually.
It sounds like this installation includes a custom dialog that doesn't properly handle either MODE SILENTMODE or RECORDMODE. For silent installations to work properly, it needs to call SilentWriteData and SilentReadData when appropriate.
If you are the author of this installation (whether original or inherited), you should handle this case. If you are not the author and are trying to install this installation silently, you should contact the vendor, or (as Glytzhkof suggests) ask on a more relevant site for workarounds.
I think the response file will only contain the actual answers that were input during the original response file creation session. Did this missing dialog show up during the original setup run? Reboot dialogs and rare to display dialogs are often missing from the response file.
It could also be that the missing dialog is a custom made dialog and not a built-in Installshield dialog. I suppose this could mean it doesn't behave in the standard way.
How complex is this setup? How many systems are you deploying to? To reliably deploy files like these it is common to use "setup capture" and repackage as MSI files - so called application repackaging.
Depending on how many setups you have, how important they are and how many machines they need to reliably work on it might be worth capturing them. This is a highly complex task at times, but yield more reliable deployment once done right. Personally I find the biggest benefit of repackaging is the availability of a reliable uninstall - provided you have cleaned up the capture properly. Otherwise you have to create response files for the uninstall too. Very clunky and error prone - even when done well.
You might want to take this discussion to serverfault.com - the system administrator equivalent to stackoverflow.com. You can also have a look here: http://unattended.sourceforge.net/installers.php

Resources