getting the last line of jenkins build - selenium

I plugged in selenium into jenkins build. For some reason, the tests are hanging. Like it completes the full build except for one. The last test hangs. Is there a way to abort the Jenkins build, and run the last test by itself.? When you abort the jenkins build the last line of the console output is the test that failed. So I want to get the last line of the console.output and use that to run the test that hanged.
For example, when the build is aborted, the last line might be
tests/onboarding finished.
I want to get the last line and run the test for tests/onboarding. How do I grep for the last line when a jenkins build is aborted?

If you are on Unix based system, you can look for the build log like this:
tail -1 path/to/build/file.log
or
awk 'END{print}' path/to/build/file.log
or
sed -n '$p' path/to/build/file.log

Related

Have a wait / timeout when running selenium test suite in command prompt

When running my test suite in Selenium IDE, the tests pass as the IDE allows for enough time (30000) to find the elements.
When running my test suite using command line, the tests fail with the Timeout error below.
I have tried adding a timeout to the command by adding the words "--timeout [60000]" to the command line,
example:
selenium-side-runner --timeout [60000] -c "browserName=chrome" "Desktop/SIDE with CMD/CmdWithoutInit2.side"
I have also added "Pause" and various "waits" to the actual tests in Selenium IDE, all of which work in IDE but are null when running in Command.
TimeoutError: Waiting for element to be located By(css selector,
#select2-ProjectID-v1-container > .select2-selection__placeholder)
Wait timed out after 15051ms
I need a way to run the Selenium IDE (.side) test suite using command line. To do this I need CMD to give enough time for the test to find each element, like the IDE does. I am hoping there is a short few words I can add to the command itself.
The answer is to add --timeout 6000 to the command line.
Example, in command prompt, run test by entering
selenium-side-runner --timeout 60000 -c "browserName=chrome" "Desktop/Name.side"
Timeout syntax does not include square bracers, can remove --debug if needed, doesn't provide useful info on actual running test only on running side-runner itself.

How can I redirect the output of the CMake "execute_process" command to STDOUT in real-time?

I am working on a project that needs to execute a system process from a CMake script that may take a while to run. The problem is the entire time the process is running I get no feedback about whether it is succeeding or not. Since the process may take a few minutes to run it may appear as though it froze even though it is still silently working.
At the end of the process I can get the output in a CMake variable and print all of the things that happened during that time:
execute_process(COMMAND some system command
OUTPUT_VARIABLE command_output
)
# ... nothing happens for a few minutes while the process executes
# All of the output from the past few minutes is printed all at once.
message(STATUS ${command_output})
It would be much nicer if I could just redirect the process output directly to STDOUT so I could see output of the process while it is executing... Is there any way to do this?

TFS 2015 Command Line build task fails after executing xUnit tests but there's no error/issue

In the build definition in TFS 2015, I've got a Command Line step that runs the following command:
xunit.console.exe \PathToTests\Tests.dll -xml \PathToResultsFolder\Results.xml
During the build, I can see the tests are being discovered and executing and everything's looking good.
But if I don't check "Continue on error" in the Command Line step, after the tests run and the result XML file has been saved, the step fails with the following error:
Task CmdLine failed. This caused the job to fail. Look at the logs for the task for more details.
But there's actually no error or anything I can see. The tests have run and the XML file has saved properly and is able to published to TFS. And I don't see an error like this if I run the command from the build machine.
Any ideas?

Start program via ssh in Jenkins and using it in Jenkins build

Hello people.
I'm using Jenkins as CI server and I need to run some performance test using Jmeter. I've setup the plugin and configured my workspace and everything works ok, but I have to do some steps manually and I want a bit more of "automation".
Currently i have some small programs in a remote server. These programs make some specific validations, for instance (just to explain): validates e-mail addresses, phone numbers, etc.
So, before I run the build in jenkins, I have to manually start the program (file.sh) I want:
I have to use putty (or any othe ssh client) to conect to the server and then run, for instance, the command
./email_validation.sh
And the Jmeter test runs in a correct way, and when the test is done I have to manually "shut down" the program I started. But what I want is trying to start the program I need in Jenkins configuration (not manually outside Jenkins, but in "execute shell" or "execute remote shell using ssh" build step).
I have tried to start it, but it get stuck, because when Jenkins build finds the command
./email_validation.sh
the build stops, it waits for the command to finish and then it will continue the other build steps, but obviously, I need this step not to finish until the test is executed.
Is there a way to achieve this? Thanks
Run your command as a background process by adding the & symbol at the end of the command and use the nohup command in case the parent process gets a hangup signal, e.g.
nohup /path/to/email_validation.sh &
If the script produces any output, it will go by default to the file nohup.out in the current directory when the script was launched.
You can kill the process at the end of the build by running:
pkill email_validation.sh

Jenkins succeed when unit test fails (Rails)

I'm barely started to use Jenkins and this is the first problem I've had so far. Basically my jenkins job always succeed even when an error happened in some of the tests. This is what I'm running in the shell config:
bundle install
rake db:migrate:reset
rake test:units
rake spec:models
Thing is that Jenkins only reports a failure when the task which fails is the last one. For instance, if I put "rake test:units" the last task it will notify an error if something go wrong. Using this configuration I only get error reports for the rspec tests but not for the unit tests.
Anyone wondering why I don't only use rspec or unit test, we are currently migrating to rspec but this problem is still painful.
This is part of the log from Jenkinsm as you can see one of the unit test fails but jenkins still finish with success.
314 tests, 1781 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [/var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p1...]
Tasks: TOP => test:units
(See full trace by running task with --trace)
Lot of rspec tests here....
Finished in 3.84 seconds
88 examples, 0 failures, 42 pending
Pushing HEAD to branch master of origin repository
Pushing HEAD to branch master at repo origin
Finished: SUCCESS
Jenkins executes the commands you type into a Build Step box by writing them to a temporary file and then running the script using /bin/sh -xe.
Usually this produces the desired effect: Commands are executed in sequence (and printed) and the script aborts immediately when a command fails i.e. exits with non-zero exit code.
If this is not happening to you, the only reason can be that you have overridden this behavior. You can override it by starting the first line of your Build Step with these two characters: #!.
For example, if your Build Step looks like this:
#!/bin/bash
bundle install
rake db:migrate:reset
rake test:units
rake spec:models
Then it means Jenkins will write the script to a temporary file and it will be executed with /bin/bash. When invoked like that, bash will execute commands one-by-one and not care if they succeed. The exit code of the bash process will be the exit code of the last command in the script and that will be seen by Jenkins when the script ends.
So, take care in what you put on the first line of the Build Step. If you do not know how shell works, do not put a hash-bang at all and let Jenkins decide how the script should be run.
If you need more control over how the Build Step is executed, you should study the man page of the shell you use to find out how to make it behave the way you want. Jenkins doesn't have much of a role in here. It just executes the shell you wanted the way you wanted.
Jenkins can only see the result code of the last command run so it has no way of knowing what the result of rake test:units is.
The easiest thing is probably to have each command of those commands as a separate jenkins build step.
An alternative solution is change your first line to the following:
#!/bin/bash -e
This tells your script to fail if any of the commands in the script return an error.
See: Automatic exit from bash shell script on error