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

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!

Related

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()

Execution a deployment script on a remote ssh server through a Jenkins pipeline

I've got a Jenkins pipeline containing stages for source loading, building and deploying on a remote machine through SSH. The problem is about the last one. I saved the script of the following template on the remote server:
#!/bin/bash
bash /<pathTo>/jboss-cli.sh --command="deploy /<anotherPath>/service.war --force"
It works fine if executed in a terminal connected to the remote server.
The best outcome I've received through Jenkins is
/<pathTo>/jboss-cli.sh: line 87: usr/bin/java/bin/java: No such file or directory
in Jenkins console output.
Tried switching between bash and sh, exporting path to java in the pipeline script etc.
Any suggestions are appreciated.
Thanks!
p.s. Execution call from Jenkins looks like:
sh """
ssh -o StrictHostKeyChecking=no $connectionName 'bash /<pathToTheScript>/<scriptName>.sh'
"""
line 87: **usr/bin/java/bin/java**: No such file or directory
As per error line it is considering path from usr not /usr. Can you check if this is what the problem is?
Sorry, I know this should be in comments section but I don't have right to add comments yet.

In Jenkins, on a Windows remote connected through Cygwin sshd, how to run an sh pipeline step?

We are porting our Jenkins pipeline to work on Windows environments.
The Jenkins' master connects to our Windows remote -named winremote- using Cygwin sshd.
As described on this page, the Remote root directory of the node is given as a plain Windows path (in this case, it is set to C:\cygwin64\home\jenkins\jenkins-slave-dir)
This minimal pipeline example:
node("winremote")
{
echo "Entering Windows remote"
sh "ls -l"
}
fails with the error:
[Pipeline] echo
Entering Windows rmeote
[Pipeline] sh
[C:\cygwin64\home\jenkins\jenkins-slave-dir\workspace\proto-platforms] Running shell script
sh: C:\cygwin64\home\jenkins\jenkins-slave-dir\workspace\proto-platforms#tmp\durable-a739272f\script.sh: command not found
SSHing into the Windows remote, I was able to see that Jenkins actually created workspace subdirectory in C:\cygwin64\home\jenkins\jenkins-slave-dir, but it is left empty.
Is there a known way to use the sh pipeline step on such a remote ?
A PR from blatinville, that was merged a few hours after this question, solves this first issue.
Sadly, it introduces another problem, described in the ticket JENKINS-41225, with the error:
nohup: failed to run command 'sh': No such file or directory
There is a proposed PR for a quickfix of this issue.
Then there is a last problem with how the durable-task-plugin evaluate if a task is still alive using 'ps', with another PR fixing it.
Temporary solution
Until those (or equivalent) fixes are applied, one could compile a Cygwin compatible durable-task-plugin with the following commands:
git clone https://github.com/Adnn/durable-task-plugin.git -b cygwin_fixes
cd durable-task-plugin/
mvn clean install -DskipTests
Which notably generates target/durable-task.hpi file, which can be used to replace the durable-task.jpi file as installed by Jenkins in its plugins folder. It is then required to restart Jenkins.

Jenkins shell script to git pull to production directory

I have a really simple Jenkins setup where it pulls down updates from BitBucket and runs some tests which all work lovely.
Jenkins and the testing website are both the same server so I want it to head off to my live website directory and pull down the repository that its just tested.
When I try and access : /var/www/vhosts/mysite/httpdocs/whatever/ I get a script error stating that this isn't a directory.
What would be the best way to do this?
Error is as follows:
[Pheme CI] $ /bin/sh -xe /tmp/hudson5490778292870793122.sh
+ cd /var/www/vhosts/mysite.co.uk/httpdocs/
/tmp/hudson5490778292870793122.sh: line 2: cd: /var/www/vhosts/mysite.co.uk/httpdocs/: Not a directory
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Edit this appears to be a permissions issue will update when its sorted!
Right simply put this comes down to the Jenkins user not having access to the directory I needed it to, I simply
chown jenkins <dir>
and it all works fine! There is probably a better way to do this.

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