Jenkins builds failing with a missing file error even though the file is there - linux

I have a Jenkins server running and have a couple of builds that are all working. However, this morning when I tried to add another one it kept failing with the error -
[test.gov] $ /bin/sh -xe /tmp/hudson7055290339554583413.sh
+ ./opt/jenkins/build.sh
/tmp/hudson7055290339554583413.sh: line 2: /opt/jenkins/build.sh: No such file or directory
Build step 'Execute shell' marked build as failure
The shell script is at that path and has that name. If I make it ./opt/jenkins/build.sh it still fails with the same error. The command I have in the "Execute Shell" section in the "Command" text box is /opt/jenkins/build.sh. I tried ./opt/jenkins/build.sh as well.
The script is on a CentOS system btw.
This is the script I am trying to run -
echo "git pull"
cd /var/www/path/for/my_website/docroot/
git checkout master
git pull
echo "change ownership to apache"
chown -R apache:apache *
echo "running drush commands"
drush updb -y
#drush fra -y
drush cc all

Often the "build.sh: No such file or directory" error actually means that the shebang line within build.sh does not point to an executable file. Check the contents of build.sh to make sure that path exists.

Sometimes for your path in the shell command, a "." may not work. Instead, use the macro expression to get the workspace.
So for example: %WORKSPACE%/opt/jenkins/usda_gov_build.sh
This will give the shell command the exact path of the file in your jobs workspace.

Related

Why doesn't my crontab job find the correct file path?

echo "Enter base root directory ..."
cd ./base
export PYTHONPATH=`pwd`
echo "Downloading resources ..."
python3 ./util/fetch.py -o ./ downloadResources
echo "Exit from base and enter the upper level directory ..."
cd ..
python3 ./test/data_poster.py
echo "done ..."
I have a crontab job as listed above(auto_run.sh). What it does:
In the root directory of the current project, to enter the base/ subdirectory
under base/, it download some resources files
The it exited from the base/ directory and in the root directory, to run 'data_poster.py'
The problem occurs. In the log of the crontab, it complains that:
python3: can't open file './util/fetch.py': [Errno 2] No such file or directory
python3: can't open file './test/data_poster.py
Why can't the cronjob execute the python script in both cases? The path to the two scripts are right. If I just run 'sh auto_run.sh' without using cronjob, it works all right.
So what's the problem?
You must explicitly set up your environment in the crontab script. That's because cron runs from a non-interactive, non-login shell.
When your cron script runs cd ./base, there is no "." (current directory) as there was no login shell to set one. Use full paths.
See This question on stackexchange for more info.

bash changing directory when started

I have both Bash on Ubuntu on Windows and Cygwin bash installed on my machine, and both are setup to have the same ~ folder (via /mnt/c/source and /cygdrive/c/source respectively).
When I start Ubuntu's bash prompt via bash --login -i (or just bash --login) from any directory, I get a prompt running from within that directory; however, when I start Cygwin's bash via the same command, the current directory is overridden, and the prompt is always at ~. See the screenshots for a simple example.
My user directory's .bashrc and .bash_profile are of course the same, as both are using the same user directory. I've looked into Cygwin's /etc/bash.bashrc and there doesn't seem to be anything there to change my current directory, and there aren't any other relevant files in /etc.
What could be causing Cygwin's bash to change directory?
you just add a command "cd /dir_you_want" at the bottom of ~/.bashrc in cygwin
I've figured it out, so in case anyone runs into the same issue:
There's one file I neglected to look into, because I didn't know it exists, /etc/profile. In Cygwin, by default it has the following section in it:
# Make sure we start in home unless invoked by CHERE
if [ ! -z "${CHERE_INVOKING}" ]; then
unset CHERE_INVOKING
else
cd "${HOME}" || echo "WARNING: Failed attempt to cd into ${HOME}!"
fi
Disabling that solves the issue of course.

Git commands in cron job

I am new to cron jobs. I want to run git commands through cron job.
I just tried a simple one with 'git status'.
I created a script
#!/bin/bash
echo git status
It is working when I run the script directly in the git view but not working in crontab.
I created the crontab as
* * * * * /path/to/script >> path/to/outputfile.
Please help me.
EDITED:
Please provide any sample program for running simple git commands in cronjob.
First off, you don't need an
echo `git status`
to output text, if you call the script with the >>. That way, you just echo the output you'd get anyway.
Concerning your problem, as was already discussed, you can give the direct path to git (such as /usr/local/bin/git). Furthermore, the script probably won't be called in the directory where your git repo lies; you have to cd there first, e.g.
#!/bin/bash
cd <wherever your repo lies>
/usr/local/bin/git status
and then add that script in your crontab as you already did. Hope that helps.

Creating a text file via SSH shell

I am trying to create a BASH shell script that runs through SSH on my shared hosting account to automate the git website control system detailed in:
http://danielmiessler.com/study/git/#website.
So far my bash script is right out of the above article:
cd ~/mydomains; mkdir $name.git;
cd ~/mydomains/$name.git; git init --bare;
/bin/vi ~/domains/$name.git/hooks/post-update
The first 2 lines work as expected.
when I add the third line the script seems to freeze up. the path to vi is /bin/vi in my environment.
Directly from the article I want the to perform the following:
vi /path/website.git/hooks/post-update
then insert:
GIT_WORK_TREE=/path/htdocs git checkout -f
Then close the file.
Could anyone offer me some advice on what to do now?
Why are you try to use vi in script just to add line into file?
Problem is that vi is interactive, but you're looking how to automate this ;-)
You should use
echo "GIT_WORK_TREE=/path/htdocs git checkout -f" >> ~/domains/$name.git/hooks/post-update
I believe you need to make the hook script executable before git will use it.
chmod +x /path/website.git/hooks/post-update
After that, after pushing, the script ought to be executed.

TCL / TCLSH no such file or directory

I'm trying to build a software called Slicer3 on Windows 7 which features a "super build".
It's a All-in-one TCL Script to checkout and build Slicer3.
I ran CYGWIN and navigated til the correct directory, then ran the script and got:
$ ./Slicer3-svn/Scripts/getbuildtest.tcl
couldn't read file "./Slicer3-svn/Scripts/getbuildtest.tcl": no such file or directory
Obviously I am sure that the file exists and I gave it 777 permission. I'm running cygwin as admin.
The beginning of the tcl file's content is:
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$#"
So I tried commenting out line 3 and running directly
$ tclsh ./Slicer3-svn/Scripts/getbuildtest.tcl
but got the same error.
Any idea?
I will try to help troubleshooting as much as I can:
Determine if you have tclsh installed and it is in the PATH:
$ tclsh
Determine if tclsh works for a simple script:
$ echo puts hello > hello.tcl; tclsh hello.tcl
Determine if the script exists and readable:
$ cat ./Slicer3-svn/Scripts/getbuildtest.tcl
$ cd ./Slicer3-svn/Scripts
$ cat getbuildtest.tcl
As far as line-ending (DOS CRLF vs. Unix LF):
$ cd ./Slicer3-svn/Scripts
$ sed 's/\r\n/\n/g' getbuildtest.tcl > getbuildtest_new.tcl
$ tclsh getbuildtest_new.tcl
This way, we can narrow down the problem, should any of the steps failed.
Description: TCLSH couldn't read file: no such file or directory.
Possible reason: TCLSH under CYGWIN does not resolve windows PATH's properly, and cannot find the files.
Workaround: move the script within the CYGWIN path.
just moving the script to a "simpler" path works for me. I'm not that sure about the reason, neither how to solve this misbehaviour.

Resources