Check if File Exists Informatica Workflow - informatica

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.

Related

gdb run program in a loop until a breakpoint is reached then display stacktrace

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.

What could cause unzip command returning -1 in my scenario?

I run unzip via a system() call in my C++ code in below format:
/usr/bin/unzip -o -q /<my_path_to_zip_file>/cfg_T-KTMAKUCB.zip -d /<my_path_to_dest>/../
This will almost 90% of times succeed. I cannot understand what could make it fail time to time with -1 return code. Any ideas?
According my local man system,
The value returned is -1 on error (e.g. fork(2) failed), and the return status of the command otherwise.
and the POSIX spec says,
If a child process cannot be created, or if the termination status for the command language interpreter cannot be obtained, system() shall return -1 and set errno to indicate the error
Finally, the manpage for unzip lists various return codes, but -1 isn't among them.
If the command itself can't return -1, the problem is probably with the initial fork/exec, due to something like a system-wide or per-user limit (memory exhausted; process table full; maximum processes, open files or VM size limit for the user etc. etc).
You should be checking errno when system fails anyway. Running the whole thing under strace -f will also show what happens.

How to mark Jenkins builds as SUCCESS only on specific error exit values (other than 0)?

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.

Hudson/jenkins does not fail on errors

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.

Checking return value of a C++ executable through shell script

I am running a shell script on windows with cygwin in which I execute a program multiple times with different arguments each time. Sometimes, the program generates segmentation fault for some input arguments. I want to generate a text file in which the shell script can write for which of the inputs, the program failed. Basically I want to check return value of the program each time it runs. Here I am assuming that when program fails, it returns a different value from that when it succeeds. I am not sure about this. The executable is a C++ program.
Is it possible to do this? Please guide. If possible, please provide a code snippet for shell script.
Also, please tell what all values are returned.
My script is .sh file.
The return value of the last program that finished is available in the environment variable $?.
You can test the return value using shell's if command:
if program; then
echo Success
else
echo Fail
fi
or by using "and" or "or" lists to do extra commands only if yours succeeds or failed:
program && echo Success
program || echo Fail
Note that the test succeeds if the program returns 0 for success, which is slightly counterintuitive if you're used to C/C++ conditions succeeding for non-zero values.
if it is bat file you can use %ERRORLEVEL%
Assuming no significant spaces in your command line arguments:
cat <<'EOF' |
-V
-h
-:
-a whatnot peezat
!
while read args
do
if program $args
then : OK
else echo "!! FAIL !! ($?) $args" >> logfile
fi
done
This takes a but more effort (to be polite about it) if you must retain spaces. Well, a bit more effort; you probably use an eval in front of the 'program'.