Jenkins - java.io.IOException: Cannot run program "/usr/local/bin/bash" - shell

I am using Jenkings in Linux_Machine_1. It have around 20 jobs(successfully running jobs)
I copied .jenkins folder to Linux_Machine_2. I started Jenkins in Linux_Machine_2.
I tried to run one of the jobs and I am getting below error:
Started by user anonymous
Building in workspace /home/portaldev/.jenkins/workspace/Trunk_Build
[Trunk_Build] $ /usr/local/bin/bash -xe /tmp/hudson1846171411013031358.sh
FATAL: command execution failed
java.io.IOException: Cannot run program "/usr/local/bin/bash" (in directory "/home/portaldev/.jenkins/workspace/Trunk_Build"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:763)
at hudson.Launcher$ProcStarter.start(Launcher.java:353)
at hudson.Launcher$ProcStarter.join(Launcher.java:360)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:91)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:60)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:804)
at hudson.model.Build$BuildExecution.build(Build.java:199)
at hudson.model.Build$BuildExecution.doRun(Build.java:160)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:586)
at hudson.model.Run.execute(Run.java:1576)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:241)
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:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021)
... 16 more
Build step 'Execute shell' marked build as failure
An attempt to send an e-mail to empty list of recipients, ignored.
Finished: FAILURE
After I created simple job Test_Job (no build scripts) in the Linux_Machine_2. And build, even I am getting same type of error.
I tried by execute permission to all .jenkins folder
chmod +x .jenkings/
Even same out error output.
I run which bash and it gave output /bin/bash.

say ls -l /usr/local/bin/bash on machine 1 to see if there's a symbolic link from /usr/local/bin/bash to /bin/bash. if yes, then create the same link on machine 2:
cd /usr/local/bin
ln -s /bin/bash .

Related

jenkins does not find git on mac

Jenkins building a simple hello world app fails with this command
Caused by: hudson.plugins.git.GitException: Command "git init /Users/jenkins/workspace/helloworld" returned status code 1:
stdout:
stderr: xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2430)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2360)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2356)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1916)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:988)
... 11 more
[Pipeline] }
[Pipeline] // node
[Pipeline] }
Cloning repository https://github.com/xxx/demo_qmake_hello_world.git
> git init /Users/jenkins/workspace/helloworld # timeout=10
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: Error cloning remote repo 'origin'
Finished: FAILURE
Obviously the Jenkins java SSH connection does not find git on my mac.
But why? Yes the execution context seems to be different, not the same PATH...But adding the PATH to the node's ENV did not work. Other people had the same issues, and only got this answer, but it just does not work.
Update
There is an option on the node to specify Git Tool location. I added it like this.
Git seems to be found now. But now the permissions are unsufficient.
Caused by: java.io.IOException: Cannot run program "/usr/local/git/bin" (in directory "/Users/jenkins/workspace/helloworld"): error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:252)
at hudson.Proc$LocalProc.<init>(Proc.java:221)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:936)
at hudson.Launcher$ProcStarter.start(Launcher.java:454)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2423)
... 15 more
Caused by: java.io.IOException: error=13, Permission denied
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 20 more
With ls -la /usr/local/git/bin I have checked the ownership.
git belonged to root, but I have changed it to jenkins.
Still this seems not enough, still get the permission error...
-rwxr-xr-x 1 jenkins wheel 5941024 Nov 8 2017 git
Update 2
The correct path in the Node's tools is /usr/local/git/bin/git. That was the problem.
which git - is the command to find git location on mac

Mac OSX Jenkins Sonar with Xamarin issue

I have been trying to run SonarQube in jenkins for my Xamarin project. I was able to build the project successfully using jenkins.
My SonarScanner is installed like here,
I am getting following error, when i tried to run the sonar scanner through my builder.
> [app] $ dotnet /Users/zumry/.jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/sonar-scanner/SonarScanner.MSBuild.dll begin /k:appid /n:xamarin_app /v:1.0 /d:sonar.host.url=http://localhost:9000 ******** sonar.login=admin sonar.password=admin
> FATAL: Cannot run program "dotnet" (in directory "/Users/zumry/.jenkins/workspace/app"): error=2, No such file or directory
java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
Caused: java.io.IOException: Cannot run program "dotnet" (in directory "/Users/zumry/.jenkins/workspace/app"): error=2, No such file or directory

jenkins permission denied while running cd command

I am fairly new to macOS and I am trying to run a shell script through Jenkins for a maven project.
I just don't know how to give/change permission so that Jenkins can even change a directory.
Command I am trying to run:
#!/bin/bash
export JAVA_HOME=$(/usr/libexec/java_home)
export M2_HOME=/usr/local/apache-maven/apache-maven-3.5.3
export PATH=$PATH:/usr/local/apache-maven/apache-maven-3.5.3/bin
cd /Users/User1/Documents/QA_Automation/Selenium/workspace/TestProject
mvn clean install -Dtest=IOSTDMobileTest -Dwebtest.browser=Chrome
Output I am getting:
Building in workspace /Users/Shared/Jenkins/Home/workspace/Test job 2
[Test job 2] $ /bin/bash
/Users/Shared/Jenkins/tmp/jenkins1874710180338230332.sh
/Users/Shared/Jenkins/tmp/jenkins1874710180338230332.sh: line 7: cd:
/Users/User1/Documents/QA_Automation/Selenium/workspace/TestProject:Permission denied
I had the same problem with the next task:
cd /home/allex/NetBeansProjects/HelloWorld/
pwd
javac HelloWorld.java
java HelloWorld
When I executed it I got the "Permission errors like you" but in my interactive CLI I didn't have problem to access to the directory. Then I realized that the user who execute the command in Jenkins is "jenkins" who didn't have rights access to that directory by executing this command:
ls -ld /home/allex/
drwxr-x---. 87 allex allex 4096 Nov 19 08:57 /home/allex/
As you can see the user jenkins has no permissions over that directory. Then what I did was add the user jenkins to the group allex with the next command:
usermod -a -G allex jenkins
And that was all. It's working.

NiFi Build Errors

I'm trying to build Apache NiFi after cloning it from https://github.com/apache/nifi and it keeps failing on the tests on the nifi-standard-processors project. I opened up the output file in the surefire-reports directory and there's the below error that it can't run program "cmd" in directory /var/test, because no such file or directory exists. The first time I ran the install it didn't exist, but I created it and I still get the error message. I do a sanity check every time to make sure the directory still does exist. Does anyone have any idea what might be causing this issue? I'm only taking a very few steps to do this. They are posted below. I'm logged on as root on a CentOS Linux VM. Thanks in advance for any help.
Steps:
cd /tmp
git clone https://github.com/apache/nifi
cd nifi
mvn clean install
[main] ERROR org.apache.nifi.processors.standard.ExecuteProcess - ExecuteProcess[id=a8d6b3a3-befa-4b74-a962-330bd021ec7b] Failed to create process due to java.io.IOException: Cannot run program "cmd" (in directory "/var/test"): error=2, No such file or directory: java.io.IOException: Cannot run program "cmd" (in directory "/var/test"): error=2, No such file or directory
I believe this is due to a recent commit "solving" this ticket[1]. I actually already reopened[2] it due to failures on TravisCI and the contributor is currently working on a fix.
In order to build now, you can tell maven to "skip tests" by running the command with the proper flag: mvn clean install -Dmaven.test.skip=true
[1] https://issues.apache.org/jira/browse/NIFI-2905
[2] https://issues.apache.org/jira/browse/NIFI-2905?focusedCommentId=15603258&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-15603258

Xcode integration in Jenkins - permission denied

i'm trying to built my Xcode Projekt with Jenkins, but when i built i get the error
Started by user anonymous Building in workspace /Users/icash/.jenkins/jobs/first-ios-app/workspace JDK installation
skipped: Unknown CPU name: mac os x Checkout:workspace / /Users/icash/.jenkins/jobs/first-ios-app/workspace -
hudson.remoting.LocalChannel#13ed9bc5 Using strategy: Default Last Built Revision:
Revision abc22103fa068c103fabf76999ec03d8710957f4 (origin/master)
Checkout:workspace / /Users/icash/.jenkins/jobs/first-ios-app/workspace -
hudson.remoting.LocalChannel#13ed9bc5 Fetching changes from 1 remote Git repository Fetching upstream changes
from git://github.com/shinetech/jenkins-ios-example.git Commencing build of Revision
abc22103fa068c103fabf76999ec03d8710957f4 (origin/master) Checking out Revision abc22103fa068c103fabf76999ec03d8710957f4
(origin/master) JDK installation skipped: Unknown CPU name: mac os x Working directory is
/Users/icash/.jenkins/jobs/first-ios-app/workspace [workspace] $ /users/icash/dev/ -version FATAL: Cannot run program
"/users/icash/dev/" (in directory "/Users/icash/.jenkins/jobs/first-ios-app/workspace"): error=13, Permission denied
java.io.IOException: Cannot run program "/users/icash/dev/" (in directory
"/Users/icash/.jenkins/jobs/first-ios-app/workspace"): error=13, Permission denied
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 au.com.rayh.XCodeBuilder.perform(XCodeBuilder.java:120)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:703)
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:473)
at hudson.model.Run.run(Run.java:1410)
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=13, Permission denied
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)
although i gave .jenkins folder all permission.
Looks like that it is trying to run a directory (/users/icash/dev/) as if it is an app. Seems something is configured incorrectly. Search for /users/icash/dev/ in your top-level config.xml; if not found search for a pattern ${var_name}/dev. If not found there, look in config.xml for your job.
I bet your build step looks like:
/users/icash/dev/$SOMEVARIABLE -version
and SOMEVARIABLE is not defined in the environment where Jenkins is running. That is why it expands into an empty string. What is left is the path to a directory and you cannot execute that.
If you need some environment variables in Jenkins, you can set them by going to Jenkins UI -> Manage Jenkins -> Configure System. Then add environment variables there.

Resources