Script 1 has imported Script 2
Script 1 invokes a method on Script 2
If some condition is met, Script 2 must exit and Script 1 must resume.
If this is possible, how do I achieve it and how Script 1 understands Script 2 has exited?
I do aware of return statements, but function is nested and hence 'return' would return to the previous function. I want to stop the entire script (Script2), without affecting Script 1.
Thanks in advance.
Related
I am trying to debug a very sporadic issue in my application. If ran ~1000 times my application surely hits a certain line it shouldn't and I would like to view the stack.
I tried using a gdb script cmd.gdb for this:
set logging overwrite on
set pagination off
set $n = 1000
break file.c:496
while $n-- > 0
ignore 1 9
condition 1 global_var == 10
run
end
How should I modify this script in order to print the stack when the breakpoint is reached?
I tried adding this after "run":
if $_siginfo
bt
loop_break
end
but it doesn't seem to work.
Actually, I have a Github repo with a Python-GDB extension, which does exactly the same thing as You have described, but with some more functionality.
You can just clone the repo:
git clone https://github.com/Viaceslavus/gdb-debug-until.git
and feed the python script to GDB with the following command inside GDB:
source <python script path>
Then, according to your example, you should run the next command:
debug-until file.c:496 --args="" --var-eq="global_var:10" -r=1000
*some remarks:
file.c:496 here is a starting breakpoint
"--args" parameter contains the arguments for your program
"--var-eq" is a debugging event, where 'global_var' is a variable name and '10' is a value
and finally the "-r" option specifies the number of times the program will be ran.
So all together this command will run your program 1000 times and will immediately notify You when the 'global_var' will be equal to 10.
Any additional information about the project could be found here:
https://github.com/Viaceslavus/gdb-debug-until.git in the README file.
I am trying to figure out a way to check if the file exists before running a session.
I currently have a command line task before a sessions that does the following:
IF EXIST TEST*.TXT
EXIT 0
ELSE
EXIT 1
I want to use the ErrorCode value on the link task, but I have no luck getting it to work. Is there a way to do this?
I use Command task with this command:
test -f $PMTargetFileDir/fdata.txt; echo $((1/$?))
1) If the file exists $? equals to 0.
2) If the file does not exist $? equals to 1.
So, in 1) $((1/$?)) will cause th error (division by zero). After the Command task you can add two or one of these links: first with the condition $TaskName.PrevTaskStatus=SUCCEEDED, and second with $TaskName.PrevTaskStatus=FAILED.
Create a command task just before your main session
Link this command task to main session and put link condition as $prevtaskstatus=succeeded
and write below code in Command task
head -2 /testfiledir/test.txt
Command task will fail if file does not exist and succeeds if file exist.
When I run an Execute shell build step to execute a script and that script returns 0, Jenkins flags the build as SUCCESS, otherwise it flags it as FAILURE which is the expected default behaviour as 0 means no errors and any other value represents an error.
Is there a way to mark a build as SUCCESS only if the return value matches a specific value other than 0 (e.g. 1,2,3...)?
PS: in case you're wondering why I'm looking for that, this will allow me to perform unit testing of Jenkins itself as my scripts are written to return different exit values depending on various factors, thus allowing me to expect certain values depending on certain setup mistakes and making sure my whole Jenkins integration picks up on those.
Alright, I went on IRC #jenkins and no-one new about a plugin to set a particular job status depending on a particular exit code :( I managed to do what I wanted by creating an Execute shell step with the following content:
bash -c "/path/to/myscript.sh; if [ "\$?" == "$EXPECTED_EXIT_CODE" ]; then exit 0; else exit 1; fi"
-Running the script under bash -c allows catching the exit code and prevents Jenkins from stopping build execution when that exit code is different than 0 (which it normally does).
-\$? is interpreted as $? after the script execution and represents its exit code.
-$EXPECTED_EXIT_CODE is one of my job parameters which defines the exit code I'm expecting.
-The if statement simply does the following: if I get the expected exit code, exit with 0 so that the build is marked as SUCCESS, else exit with 1 so that the build is marked as FAILURE.
/path/to/myscript.sh || if [ "$?" == "$EXPECTED_EXIT_CODE" ]; then continue; else exit 1; fi
I would use continue instead of exit 0 in case you have other items below that you need to run through.
Can handle it via the Text-finder Plugin:
Have your script print the exit-code it is about to exit with, like: Failed on XXX - Exiting with RC 2
Use the Text-finder Plugin to catch that error-message and mark the build as 'Failed' or 'Unstable',for example, if you decide RC 2, 3 and 4 should mark the build as 'Unstable', look for text in this pattern: Exiting with RC [2-4].
Create a wrapper for your shell script. Have that wrapper execute your tests and then set the resturn value according to whatever criteria you want.
I do it like this:
set +e
./myscript.sh
rc="$?"
set -e
if [ "$rc" == "$EXPECTED_CODE_1" ]; then
#...actions 1 (if required)
exit 0
elif [ "$rc" == "$EXPECTED_CODE_2" ]; then
#...actions 2 (if required)
exit 0
else
#...actions else (if required)
exit "$rc"
fi
echo "End of script" #Should never happen, just to indicate there's nothing further
Here +e is to avoid default Jenkins behavior to report FAILURE on any sneeze during your script execution. Then get back with -e.
So that you can handle your exit code as appropriate, else eventually FAIL with the returned code.
robocopy "srcDir" "destDir" /"copyOption" if %ERRORLEVEL% LEQ 2 exit 0
If robocopy exit code is less than or equal to 2 then it will exit successfully.
Robocopy Exit Codes:
0×00 0 No errors occurred, and no copying was done.
The source and destination directory trees are completely synchronized.
0×01 1 One or more files were copied successfully (that is, new files have arrived).
0×02 2 Some Extra files or directories were detected. No files were copied
Examine the output log for details.
0×04 4 Some Mismatched files or directories were detected.
Examine the output log. Housekeeping might be required.
0×08 8 Some files or directories could not be copied
(copy errors occurred and the retry limit was exceeded).
Check these errors further.
0×10 16 Serious error. Robocopy did not copy any files.
Either a usage error or an error due to insufficient access privileges
on the source or destination directories.
In my Hudson log I see error or fails, but hudson says ,that build is success.
Is it right?
This is what hudson does (run ant few times)
call f:\runGenericAntBuild.bat %WORKSPACE% f:\general-build.properties %WORKSPACE%\build\buildProjects.xml deploy %BUILD_NUMBER% %SVN_REVISION%
call f:\runGenericAntBuild.bat %WORKSPACE% f:\general-build.properties %WORKSPACE%\build\buildProjects.xml MyJavaProject %BUILD_NUMBER% %SVN_REVISION%
call f:\runGenericAntBuild.bat %WORKSPACE% f:\general-build.properties %WORKSPACE%\build\buildProjects.xml buildGrails %BUILD_NUMBER% %SVN_REVISION%
call f:\runGrailsClean.bat %WORKSPACE%\MyProject
Thanks!
Have you got a single build step that is a batch step and it contains all four call commands? If yes, thats your problem.
Your batch looks like its not doing anything with errors in any of the steps, so the status of the batch is the status of the last command (your clean step)
Either split it into four separate build steps within Hudson/Jenkins, or handle the errors in the batch script.
e.g.
call f:\runGenericAntBuild.bat your params here || exit /b 1
call f:\runGenericAntBuild.bat next params here || exit /b 2
call f:\runGenericAntBuild.bat third param here || exit /b 3
call f:\runGrailsClean.bat more param as needed || exit /b 4
This way the batch will exit with an error of 1-4 depending on the step that failed.
According to me Jenkins/Hudson is able to complete the Job successfully because it is able to complete the Job that is assigned to him. You might have not set any property in your buildProjects.xml file that says the build must fail on errors. There is a property that declares a build to fail on error.
I am creating an interpreter for my extension to HQ9+, which has the following extra command called V:
V: Interpretes the code as Lua, Brainfuck, INTERCAL, Ruby, ShellScript, Perl, Python, PHP in that order, and if even one error has occoured, run the HQ9+-ABC code again
most of them have libraries, BF and INTERCAL can be interpreted without a library, but the problem lies in ShellScript. How can I run a shellscript from my C++ application ( =the HQ9+-ABC interpreter) and when it's done, get the error code (0 = succeded, all others = failed)? So something like this:
system(".tempshellscript738319939474");
if(errcode != 0) { (rerun code); }
can anyone help me? Thanks
From man system(3):
RETURN VALUE
The value returned is -1 on error (e.g. fork failed), and the return
status of the command otherwise. This latter return status is in the
format specified in wait(2). Thus, the exit code of the command will
be WEXITSTATUS(status). In case /bin/sh could not be executed, the
exit status will be that of a command that does exit(127).
system() returns a code depending on the success or failure of whatever you called.
http://www.cplusplus.com/reference/clibrary/cstdlib/system
I remember execve call working for shell scripts that had #! interpreter in their first line for an assignment at university. If you are using system, consider trying execve as well. wait on the pid of the script could help receiving the exit status.