building failure in jenkins as build.sh: not found - jenkins

I am building a free style project in jenkins. configure setting for execute shell script as
build.sh -label $JOB_NAME -$BUILD_NUMBER -java_home $JAVA_HOME
when i try to build the project, i have a console output as build failure.
Building in workspace /var/lib/jenkins/workspace/jmxweb
[jmxweb] $ /bin/sh -xe /tmp/hudson4723307331600368596.sh
+ build.sh -label jmxweb -8 -java_home /usr/lib/jvm/java-7-oracle
/tmp/hudson4723307331600368596.sh: 2: /tmp/hudson4723307331600368596.sh: build.sh: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

According to the documentation
Builds for Non-Source Control Projects
There is sometimes a need to build a project simply for demonstration purposes or access to a SVN/CVS repository is unavailable. By choosing to configure the project as "None" under "Source Code Management" you will have to:
1 Build the Project at least once, (it will fail), but Jenkins will create the structure jenkins/workspace/PROJECTNAME/
2 Copy the project files to jenkins/workspace/PROJECTNAME/
3 Build again and configure appropriately

Try running : $WORKSPACE/build.sh -label $JOB_NAME -$BUILD_NUMBER -java_home $JAVA_HOME
The error is definitely because it can't find the file where you're looking for it. explicitly specifying the path should make sure it'll look for it in the current workspace.
Good luck!

Related

I can't build and install a project with Cmake on Jenkins

I really need some help to build a simple project with Cmake with Jenkins.
I downloaded the Cmake plugin on Jenkins.
I configured it in the job :
and in Global Tool Configuration :
But then it doesn't work. Here are the end of the logs before the Jenkins build fails :
+ ls
CMakeLists.txt
MathFunctions
TutorialConfig.h.in
build
tutorial.cxx
[build] $ cmake /var/jenkins_home/workspace/Project
ERROR: Cannot run program "cmake" (in directory "/var/jenkins_home/workspace/Project/build"): error=2, No such file or directory
Build step 'CMake Build' marked build as failure
Finished: FAILURE
I don't understand why there is no proper step-by-step tutorial to create something that common as a Cmake build with Jenkins.
In the end, I managed to pull it off.
I uninstalled the Cmake plugin which seems to be useless apparently...
And I simply installed Cmake manually on the Jenkins container.

Jenkins can't find make.exe

I'm trying to install jenkins on windows and I have Cygwin.
I provided the bash.exe path to jenkins and add a job which executes a .sh file.
The output is like:
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Build_Release
[Build_Release] $ C:\cygwin64\bin\bash.exe -xe C:\WINDOWS\TEMP\jenkins8276366787192439492.sh
+ cd /cygdrive/d/01-Avelabs/001-Projects/001-VGTT/001-Repos/P2.4.0.5/host/AdasHost/Application/
+ ./BuildHost.sh
./BuildHost.sh: line 2: make: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
What am I missing?
To get you going (the problem is not obvious but it should be easy enough to debug): Add a "set" command at the top of the script to dump the environment variables, including the PATH. You will very likely find that PATH is not in any of the folders listed in the value of the PATH env var. (You could also put simply, "echo $PATH".)
Some possibilities:
When I start bash in Windows I typically inherit the Windows path, but not the Linux path: /cygdrive/c/windows/system32 is included, but /bin is not. So, even basic Linux commands like "ls" result in "command not found" errors. I'll typically start a bash session with "export PATH=/bin:$PATH" to get around this.
Even if you initialize the path with a .bash_profile script, the user under which Jenkins is executing is probably not executing the same initialization script.
Finally - and not meaning to say "Is it plugged in? - but: I ran a clean Cygwin install and did not get make by default. So be sure it is included in /your/ installation!

Get sourcecode into Jenkins WORKSPACE subdirectory

Is it possible to configure Jenkins to get source code into a subdirectory of a %WORKSPACE%? Right now the source gets pulled into %WORKSPACE% and for the build output I explicitly specify a directory outside of the %WORKSPACE%.
Ideally I would like to have something similar to this:
%WORKSPACE%\source for source code and %WORKSPACE%\artifacts for build outputs. Is it possible to have this configuration?
Create a 'run batch command' build step and use xcopy, this is presuming jenkins is running on a Windows machine, if it's a deployment directory then make it a post build step.
cd c:/
xcopy /Y "c:/program files 86/junkies/workspace/app" "c:/path to new directory"
This is just a guess at your directories, replace with correct ones, the /Y forces it to be overwritten every time it's copied.

What's the working directory in Jenkins after executing a shell command box?

I'm looking at a Jenkins job and trying to understand it.
I have an Execute shell command box in my Build section:
> mkdir mydir
> cd mydir
>
> svn export --force https://example.com/repo/mydir .
When Jenkins is done executing that command, and moves on to the next build step, what is its working directory?
workspece-root/ or workspace-root/mydir ?
As the next step, I have Invoke top-level Maven targets (still in the Build section).
What I really want to know is: why does that execute successfully?
Is it because Jenkins automatically moves back to the workspace-root/ folder after executing a shell command box, or is it because the next job is a "top-level" job, and Jenkins therefore changes back to the workspace-root/?
Each build step is a separate process that Jenkins spawns off. They don't share anything, neither current directory, nor environment variables set/changed within the build step. Each new build step starts by spawning a new process off the parent process (the one running Jenkins)
It's not that Jenkins "move back" to $WORKSPACE. It's that Jenkins discards the previous session.
I lately saw that if you print the CWD , I would get the Project_NAME.
E.g
D:\jenkins\workspace\My_Project
Any script you might be running wont be found. Hence we can do a "CD path" before we start out scripts.
Slav's explanation is very good and I thought of complementing it by providing a real world example that shows how multiple Windows batch commands look like even if they work in the same directory:
Command 1
REM #ensures that all npm packages are downloaded
cd "%WORKSPACE%"
npm install
Command 2
REM #performs a prod-mode build of the project
cd "%WORKSPACE%"
ng build --prod --aot=true -environment=pp
So, each one ensure that current working directory points to the current project directory.

Cannot run program "gradle" in Jenkins

I've installed the Gradle plugin for Jenkins. When I try to build the project I get the following error:
[workspace] $ gradle clean -b build/build.gradle
FATAL: command execution failed
java.io.IOException: Cannot run program "gradle" (in directory "/Users/Shared/Jenkins/Home/jobs/test/workspace"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:707)
at hudson.Launcher$ProcStarter.start(Launcher.java:338)
at hudson.Launcher$ProcStarter.join(Launcher.java:345)
at hudson.plugins.gradle.Gradle.performTask(Gradle.java:201)
at hudson.plugins.gradle.Gradle.perform(Gradle.java:97)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:695)
at hudson.model.Build$RunnerImpl.build(Build.java:178)
at hudson.model.Build$RunnerImpl.doRun(Build.java:139)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:465)
at hudson.model.Run.run(Run.java:1404)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:238)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:53)
at java.lang.ProcessImpl.start(ProcessImpl.java:91)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 16 more
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE
Running the task $ gradle clean -b build/build.gradle from the command line works as expected.
I had the same issue and found that the problem for me was the gradle version in the project configuration. It was set to Default and when I set it to the gradle version I was pointing to in the plugin configuration in the Manage Jenkins > Configuration Options, It found gradle and worked properly.
This is a difficult issue to debug and I hope this saves someone else some time.
Solution Mastering_the_Object pointed out worked form me too, just to clarify steps there:
just installing Gradle plugin in Jenkins is not enough, you must also go to:
Jenkins->Manage Jenkins->Configure Jenkins->Configure system.
Under "Gradle Installations" type in name (it appears as version in project configuration), check "Install automatically" and select version. Then you can select that "Gradle version" in project configuration.
I was getting this error using the Gradle wrapper, was able to fix my broken build as follows:
Go to Manage Jenkins -> Global Tool Configuration -> Gradle -> Add Gradle, give it a name
Go to Jenkins -> (your job) -> Configure -> Build, choose "Invoke Gradle" and change the Gradle version from (Default) to the named version
When running Gradle on a CI machine such as Jenkins, it's most convenient to use the Gradle Wrapper.
On your development machine, stand in your root project directory and run
gradle wrapper
Then, check in the resulting files into your source control system. After that, you don't have to install anything on your Jenkins server if you need to change Gradle versions. Just configure your Jenkins job like this:
Quoting from the Gradle User Guide:
By distributing the wrapper with your project, anyone can work with it
without needing to install Gradle beforehand. Even better, users of
the build are guaranteed to use the version of Gradle that the build
was designed to work with. Of course, this is also great for
continuous integration servers (i.e. servers that regularly build your
project) as it requires no configuration on the server.
The jenkins can not find the gradle executable. I have never made gradle wrapper to work. Please follow the following steps:
Download gradle ( http://gradle.org/downloads),
unpack it to, e.g., /usr/local/lib/gradle ,
open /etc/profile and add the following two lines:
export GRADLE_HOME=/usr/local/lib/gradle
export PATH=$PATH:$GRADLE_HOME/bin
It works for my jenkins installation.
ps. I answer this old question, because it is a common issue when setting up gradle with jenkins. I have spent some time trying to make the gradle wrapper work without success before.
Used both #Skarab & a number of other solutions here to get it to work.
Download gradle ( http://gradle.org/downloads),
unpack it to, e.g., /usr/local/lib/gradle ,
open /etc/profile and add the following two lines:
export GRADLE_HOME=/usr/local/lib/gradle
export PATH=$PATH:$GRADLE_HOME/bin
Then under Manage Jenkins > Configure system > Gradle, defined GRADLE_HOME and gave that gradle installation a name
Then, {this could be a bug} for the project, change gradle version from Default to the one I defined above
As others have noted, this is because Jenkins can't find the gradle executable.
None of the published solutions worked for me, but I was able to fix the problem by adding the gradle bin dir to the path set in the .bashrc for the build account on the build slave. Modifying the .profile failed, and setting PATH in the jenkins node configuration also failed.
Some posts will suggest setting the gradle path in the tools menu, but no gradle entry was available there either (perhaps due to regressions / design changes in the gradle plugin?).
In any case, the best test I found (short of running the build again and watching for failure) was to run env over ssh:
ssh <host> env
and check the PATH variable defined that way; if gradle isn't in that path, you probably won't be able to run it from jenkins.

Resources