Cause a Cap Deploy error to fail a Jenkins Build - jenkins

So I'm working on a jenkins build and I'm doing a
cap deploy
in the execute shell section. What I'd like the build to do is to fail if Cap spits out any errors. For example, I just got this one:
fatal: write error: No space left on device
*** [deploy:update_code] rolling back
I tried to do something like this
cap -v deploy > deploylog
and then grepping it for errors, but it didn't write out anything to the deploy log.
Any ideas? I'm fairly new to jenkins, so if this isn't enough information let me know and I can add more :)

I would have expected the cap command to exit with a non-zero value if it encounters an error, which should make the shell step in Jenkins fail.
You can get around this by using the Text Finder plugin to search for errors in the console output.

Related

Check console logs (and stop build if needed)

We are using Jenkins (on Linux) to manage our builds.
I want to monitor the console output of all currently running jobs and abort the build if any matched pattern / exception / error is found.
For example, if the console output has IndentationError(when the job is running), I would like to automatically stop the build.
Please let me know if there are any plugins or solutions for this?
Thank you.
Jenkins will stop any build when a tool returns a non-zero exit code. If you want your build to exit on the first error, then you should configure the tools you are calling from jenkins to exit as soon as an error occurs (through command line flags etc.). Parsing console output for an error is a hacky solution at best.

Execute shell giving error in Jenkins Freestyle job

Whenever I am trying to do execute shell command in freestyle job in Jenkins, however when I try to do same thing while from pipeline, it is running successful.
Following is the error which I am getting in freestyle job:
It seems that the drive is full and there is no space left to execute this shell command. See this log:
So what you should do is to make sure that there is enough space on the drive where you run the script/command is available. Maybe you could switch to another partition or delete temporary or unused files.

When deploying a job, is it possible that the command returns after the deployment is complete?

I'm using maven to deploy my jobs on Google Cloud Dataflow, with the folowing command :
mvn compile exec:java -Dexec.mainClass=org.beam.StreamerRunner --Dexec.args="\
...
--runner=DataflowRunner \
..."
It deploys successfully, and it is pulling the log from the dataflow job and printing them on the output. I'm wondering if it is possible to tell the deployment to not pull and just returns.
Indeed, my CI tool (TeamCity) I'm using to deploy my job, is also waiting never ending.
I obviously can run the maven command in a nohup, but maybe an option does exist to exit the command after the deploy is complete.
As Alex pointed out I was calling waitUntilFinish in my code, so it dit exactly what I asked it to do.
It was fixed as soon as I removed the calle to
waitUntilFinish()

Why does user jenkins throw an error when running capistrano script from within the Jenkins interface but user root from command line does not?

I am very new to Jenkins and Capistrano. I've found existing documentation to be very fragmented when it comes to running Capistrano from within Jenkins. Having said that, I have successfully installed Jenkins and Capistrano. I've created the items and can trigger the scripts. For my initial test I am just running the default deployment script as it is out of the box.
When I run the following via Jenkins trigger:
#!/bin/bash -exl
export PATH=$PATH:/usr/local/bin
cap staging deploy
I get the error (edited for brevity):
+ USER=jenkins
+ LOGNAME=jenkins
Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.
*Nothing in /capistrano.log
When I run the same commands inside of a script from the command line I get:
+ USER=root
+ LOGNAME=root
*capistrano.log file:
---
INFO START 2016-09-29 16:50:03 +0000 cap staging deploy
INFO ------------------------------------------------------------------------
---
It appears that the jenkins user is not configured correctly and is missing some dependencies but I can't find how to fix this.
Help is appreciated. If anyone knows of a good resource for using Capistrano together with Jenkins that would also be a huge help.
Turns out the issue was a space in my workspace directory name. The directory name was not being interpreted correctly within the Jenkins script for some reason, but was fine in the bash script I ran from the command line. Thanks to my buddy Scott for figuring that one out!

Jenkins logs for a perl build file

Today I started working with jenkins and I successfully added my projects to jenkins and it says all works fine . one of the build takes more than 5 hours but didn't finish either so aborted it(while manual build takes less than 1 hour).. and while i tried to check with the log the log was not detailed. so i tried to get the logs of the perl script by running it as a shell command
usr/local/bin/perl perlscript.pl>logfile.txt
there was no log written and there was no evidence of the build triggered either cases.i'm not aware of what the problem is as both the perlscript(works fine while manually triggered) and jenkins are working properly except this project. I would like to have your help.thanks in advance
A few things you should understand about Jenkins:
Jenkins shows STDOUT as the log of the Job,
so if you redirect it to a file - nothing will be shown in the log.
Depending on how you have set it up, Jenkins may run as its own user,
which may change the behavior of your scripts.
You can confirm this by echo-ing the username at the beginning of your Execute Shell block,
for example:
echo $USER
Each Jenkins-Job is run from its own workspace -
you can confirm that location by simply printing the current working directory
at the beginning of your Execute Shell block, for example:
echo my current directory is
pwd

Resources