How to setup a Jenkins slave agent on a Mac to retrieve files using Plastic? - macos

I have a Jenkins server running on Ubuntu; sources are on Plastic and I already have a Windows slave making Android builds, so the Plastic server is well responding with Jenkins.
I try to build the project for IOS on Mac but the job fails when getting the sources with a java exception
java.io.IOException: error=2, No such file or directory
I tried to remove the source control for the job and just running some commands like :
cm status
It failed, so I updated the PATH environment variable to make it work. Now it's ok for manual commands but still not for the automatic plastic pull.
I configured the job to pull from it using the PlasticSCM Plugin using the selector :
repository "MyRepo"
path "/"
smartbranch "/My/Branch"
Here is the complete error :
[test-mac] $ cm find changeset where date between '2019-05-27T11:14:36' and '2019-05-27T11:15:43' and branch='/My/Branch' on repositories 'MyRepo' --xml --dateformat=yyyy'-'MM'-'dd'T'HH':'mm':'ss
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)
Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 192.168.1.46/192.168.1.46:49336
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1743)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
at hudson.remoting.Channel.call(Channel.java:957)
at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1059)
at hudson.Launcher$ProcStarter.start(Launcher.java:455)
at com.codicesoftware.plugins.hudson.PlasticTool.tryExecute(PlasticTool.java:97)
at com.codicesoftware.plugins.hudson.PlasticTool.execute(PlasticTool.java:57)
at com.codicesoftware.plugins.hudson.commands.CommandRunner.execute(CommandRunner.java:20)
at com.codicesoftware.plugins.hudson.commands.CommandRunner.executeAndRead(CommandRunner.java:36)
at com.codicesoftware.plugins.hudson.commands.CommandRunner.executeAndRead(CommandRunner.java:25)
at com.codicesoftware.plugins.hudson.commands.ChangesetsRetriever.getChangesets(ChangesetsRetriever.java:27)
at com.codicesoftware.plugins.hudson.commands.ChangesetsRetriever.getDetailedHistory(ChangesetsRetriever.java:36)
at com.codicesoftware.plugins.hudson.PlasticSCM.FindCsets(PlasticSCM.java:363)
at com.codicesoftware.plugins.hudson.PlasticSCM.SetUpWorkspace(PlasticSCM.java:175)
at com.codicesoftware.plugins.hudson.PlasticSCM.checkout(PlasticSCM.java:141)
at hudson.scm.SCM.checkout(SCM.java:504)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1208)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:574)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
at hudson.model.Run.execute(Run.java:1816)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Caused: java.io.IOException: Cannot run program "cm" (in directory "/Users/MyUser/Jenkins/workspace/test-mac"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:249)
at hudson.Proc$LocalProc.<init>(Proc.java:218)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:936)
at hudson.Launcher$ProcStarter.start(Launcher.java:455)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1313)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1266)
at hudson.remoting.UserRequest.perform(UserRequest.java:212)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:93)
at java.lang.Thread.run(Thread.java:748)

I think the problem could be related to the following Jenkins bug:
https://issues.jenkins-ci.org/browse/JENKINS-17157 (Enviroment variables are not loaded in ssh using cygwin)
If your slave is connecting via SSH to your Jenkins server, the environment variables are lost so you can't run "cm" commands.
The following link may be useful: (https://support.cloudbees.com/hc/en-us/articles/229724088-How-to-set-up-a-Jenkins-agent-to-have-the-same-path-as-the-user-when-connected-via-Remote-Desktop-)
In the past, we tried to connect the slave via "Java Web Start" (not via SSH) and we were not able to reproduce this issue with the lost PATH variable (it's only happening when connecting via SSH).
On the macOS:
- Running:
eg:
sudo java -jar agent.jar -jnlpUrl http://MySERVER84/computer/macOsJava/slave-agent.jnlp -secret f5dcf86e0ceed3f22c08bc27fa07d680aff3e11c25452677af4fee218bcfb1aa -workDir "/tmp"

Related

Failed to obtain Jenkins slave

In my scenario Jenkins master is available in Linux machine and i can access this in my Local windows machine also.
I created one windows slave using launch method as "Launch agent by connecting to the master".As per guidelines , i created one folder in my windows and i pasted that slave and agent jars in that folder.
While I am trying to run the slave-agent i am getting error like below. (Screenshot attached)
I tried with 2nd option as well i.e i took the provided command in Jenkins slave and i pasted that into command. again it is giving failed to connect error message. Please find below error message.
I am new to this configuration.
Do i need provide my slave machine ip into the master machine or do i need to install any other things related to this. can someone please help me out.
Failed to obtain http://ip:7394839:computer/winslave1/slave-agent.jnlp?encrypt=true
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown....etc
Slave-agent error
Issue resolved. In my case whenever we are creating new slave it is generating new IP which is not having server. Here just we are creating another node for the existing server.
Whenever we are launching the slave using agent.jar with the slave IP we are getting timed out error. Instead of going with slave IP if we go with master IP , agent is launching successfully.
Please find below example.
If i try with slave IP(Below IP)
java -jar D:\Jenkins\agent.jar -jnlpUrl we are getting error
http://120.231.140:8080/computer/My_slave_node_name_Windows10/slave-agent.jnlp -secret anHexadecimal_Long_Number5d094b1f577bc772b65b7277ac57 -workDir "D:\Jenkins"
Below IP is master IP. Agent launched successfully.
java -jar D:\Jenkins\agent.jar -jnlpUrl http://120.241.141:8080/computer/My_slave_node_name_Windows10/slave-agent.jnlp -secret anHexadecimal_Long_Number5d094b1f577bc772b65b7277ac57 -workDir "D:\Jenkins"
There is change in IP for slave and master. If i launch the slave ip from the cmd we are getting a timed out error.
The other three possibilities are
Whitelist slave IP in master Instance security groups level(all traffic or required ports).
By default windows server will block with IE security settings so diable by following below.
"Enter Server Manager in Windows search to start Server manager application. Select Local Server. Navigate to the IE Enhanced Security Configuration property, select the current setting to open the property page, select the Off option button for the desired users, and then select OK"
Configure a port number for TCP JNLP connection and whitelist it on instance security groups.
Manage Jenkins > Configure Global Security > Enable security > TCP port for JNLP agents: Fixed.

How to execute sh file from jenkins running on windows

Cygwin installed in my windows and able to execute the sh file using cmd prompt.
same Cygwin plugin has been installed in jenkins which also running in windows.
I created a job in jenkins build step->execute shell command I am giving the command as sh /cygdrive/d/539707/data/getchanges/gymBuild.sh while executing the job I am facing below exception.
NOTE 1: In Jenkins/configuration/ under shell I didn't mention any path
workspace] $ sh -xe
D:\539707\tomcat-7.0.12\temp\hudson4624102689815543789.sh FATAL:
command execution failed java.io.IOException: Cannot run program "sh"
(in directory "C:\Users\539707.jenkins\jobs\Test_Gym\workspace"):
CreateProcess error=2, The system cannot find the file specified at
java.lang.ProcessBuilder.start(ProcessBuilder.java:1047) at
hudson.Proc$LocalProc.(Proc.java:244) at
hudson.Proc$LocalProc.(Proc.java:216) at
hudson.Launcher$LocalLauncher.launch(Launcher.java:815) at
hudson.plugins.cygpath.CygpathLauncherDecorator$1.launch(CygpathLauncherDecorator.java:66)
at hudson.Launcher$ProcStarter.start(Launcher.java:381) at
hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:95)
at
hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:64)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at
hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
at hudson.model.Build$BuildExecution.build(Build.java:205) at
hudson.model.Build$BuildExecution.doRun(Build.java:162) at
hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1738) at
hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at
hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410) Caused by:
java.io.IOException: CreateProcess error=2, The system cannot find the
file specified at java.lang.ProcessImpl.create(Native Method) at
java.lang.ProcessImpl.(ProcessImpl.java:385) at
java.lang.ProcessImpl.start(ProcessImpl.java:136) at
java.lang.ProcessBuilder.start(ProcessBuilder.java:1028) ... 16 more
Build step 'Execute shell' marked build as failure
Finished: FAILURE
NOTE 2: In Jenkins/configuration/ under shell I mention C:\cygwin\bin\mintty.exe
After that below is the output
$ C:\cygwin\bin\cygpath -w C:\cygwin\bin\mintty.exe [workspace] $
C:\cygwin\bin\mintty.exe -xe
D:\539707\tomcat-7.0.12\temp\hudson4745164988293910592.sh
/usr/bin/mintty: unknown option '-x' Try '--help' for more
information. Build step 'Execute shell' marked build as failure
Finished: FAILURE
Kindly suggest How to execute sh file from jenkins running on windows
For each windows slave you can do the following to add cygwin to path assuming that your slave has cygwin installed already
Jenkins - Manage Jenkins - Manage Nodes
node - Configure
Environment variables : list of key-value pairs
add: name: PATH value: ${PATH};path-to-cygwin\bin
E.g., name: PATH value: ${PATH};d:\tools\cygwin\bin
here is the solution: Shell executable path to cygwin_home\bin\sh and in jenkins build step->execute shell command give the file name ex *.sh or clear Shell executable path and in jenkins build step->execute windows batch command sh path*.sh

Run a command shell in jenkins

I'm trying to execute a command shell in Jenkins, I'm working on Windows 7. In the console output I have this:
Building in workspace C:\Program Files (x86)\Jenkins\workspace\test
[test] $ sh -xe C:\Windows\TEMP\hudson6299483223982766034.sh
The system cannot find the file specified
FATAL: L'exécution de la commande a échoué.
java.io.IOException: Cannot run program "sh" (in directory "C:\Program Files (x86)\Jenkins\workspace\test"): CreateProcess error=2, Le fichier spécifié est introuvable
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:816)
at hudson.Launcher$ProcStarter.start(Launcher.java:382)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:97)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1744)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
Caused by: java.io.IOException: CreateProcess error=2, Le fichier spécifié est introuvable
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 16 more
Build step 'Exécuter un script shell' marked build as failure
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
Finished: FAILURE
Any idea?
For Windows slave, please use Execute Windows batch command.
For Unix-like slave like linux or Mac, Execute shell is the option.
As far as I know, Windows will not support shell scripts out of the box. You can install Cygwin or Git for Windows, go to Manage Jenkins > Configure System Shell and point it to the location of sh.exe file found in their installation. For example:
C:\Program Files\Git\bin\sh.exe
There is another option I've discovered. This one is better because it allowed me to use shell in pipeline scripts with simple sh "something".
Add the folder to system PATH. Right click on Computer, click properties > advanced system settings > environmental variables, add C:\Program Files\Git\bin\ to your system Path property.
IMPORTANT note: for some reason I had to add it to the system wide Path, adding to user Path didn't work, even though Jenkins was running on this user.
An important note (thanks bugfixr!):
This works. It should be noted that you will need to restart Jenkins in order for it to pick up the new PATH variable. I just went to my services and restated it from there.
Disclaimer: the names may differ slightly as I'm not using English Windows.
This is happens because Jenkins is not aware about the shell path.
In Manage Jenkins -> Configure System -> Shell, set the shell path as
C:\Windows\system32\cmd.exe
Error shows that script does not exists
The file does not exists. check your full path
C:\Windows\TEMP\hudson6299483223982766034.sh
The system cannot find the file specified
Moreover, to launch .sh scripts into windows, you need to have CYGWIN installed and well configured into your path
Confirm that script exists.
Into jenkins script, do the following to confirm that you do have the file
cd C:\Windows\TEMP\
ls -rtl
sh -xe hudson6299483223982766034.sh
Go to Jenkins -> Manage Jenkins -> Configure System -> Global properties
Check the box 'Environment variables' and add the JAVA_HOME path = "C:\Program Files\Java\jdk-10.0.1"
*Don't write bin at the end
I was running a job which ran a shell script in Jenkins on a Windows machine. The job was failing due to the error given below. I was able to fix the error thanks to clues in Andrejz's answer.
Error :
Started by user james
Running as SYSTEM
Building in workspace C:\Users\jamespc\.jenkins\workspace\myfolder\my-job
[my-job] $ sh -xe C:\Users\jamespc\AppData\Local\Temp\jenkins933823447809390219.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.base/java.lang.ProcessImpl.create(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:478)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:154)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
Caused: java.io.IOException: Cannot run program "sh" (in directory "C:\Users\jamespc\.jenkins\workspace\myfolder\my-job"): CreateProcess error=2, The system cannot find the file specified
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
at hudson.Proc$LocalProc.<init>(Proc.java:250)
at hudson.Proc$LocalProc.<init>(Proc.java:219)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:937)
at hudson.Launcher$ProcStarter.start(Launcher.java:455)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1853)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:427)
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Solution :
1 - Install Cygwin and note the directory where it gets installed.
It was C:\cygwin64 in my case. The sh.exe which is needed to run shell scripts is in the "bin" sub-directory, i.e. C:\cygwin64\bin.
2 - Tell Jenkins where sh.exe is located.
Jenkins web console > Manage Jenkins > Configure System > Under shell, set the "Shell executable" = C:\cygwin64\bin\sh.exe > Click apply & also click save.
That's all I did to make my job pass. I was running Jenkins from a war file and I did not need to restart it to make this work.

How do I fix my SVN checkout on my Jenkins Slave?

I have spent a few days trying to get Jenkins working with svn.
On the master, when I configure the svn url, it validates the URL.
I can do a checkout manually, and am running the slave as the same user as I did the test manual checkout.
I have tried selecting all the different versions of svn on the jenkins config page.
I have checked that entering the incorrect creds on the subversion enterCredential page results in an error, and entering the correct creds allows it to pass.
We are using basic svn auth over http (on port 8080).
The URL validation in the job config passes okay, but the job running on the slave still throws the below exception.
From my various readings of information gleened from the net I am pretty sure this is an authentication issue.
The slave is a Mac OS X, the master is a Windows Server 2008.
Jenkins in running 1.504 (Tried with 1.502). We are using svn 1.6.
Here is the exception:
Building remotely on Mac OS Test Node in workspace /Users/buildmachine/jenkins/xcode
hudson.util.IOException2: remote file operation failed: /Users/buildmachine/jenkins/xcode at hudson.remoting.Channel#1695eeb:Mac OS Test Node
at hudson.FilePath.act(FilePath.java:861)
at hudson.FilePath.act(FilePath.java:838)
at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:843)
at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:781)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1342)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:683)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:588)
at hudson.model.Run.execute(Run.java:1568)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:237)
Caused by: java.io.IOException: Remote call on Mac OS Test Node failed
at hudson.remoting.Channel.call(Channel.java:681)
at hudson.FilePath.act(FilePath.java:854)
... 11 more
Caused by: java.lang.NoSuchMethodError: org.tmatesoft.svn.core.wc.SVNBasicClient.getOperationsFactory()Lorg/tmatesoft/svn/core/wc2/SvnOperationFactory;
at hudson.scm.SvnClientManager.wrapUp(SvnClientManager.java:46)
at hudson.scm.SvnClientManager.getUpdateClient(SvnClientManager.java:67)
at hudson.scm.subversion.CheckoutUpdater$1.perform(CheckoutUpdater.java:71)
at hudson.scm.subversion.WorkspaceUpdater$UpdateTask.delegateTo(WorkspaceUpdater.java:153)
at hudson.scm.SubversionSCM$CheckOutTask.perform(SubversionSCM.java:903)
at hudson.scm.SubversionSCM$CheckOutTask.invoke(SubversionSCM.java:884)
at hudson.scm.SubversionSCM$CheckOutTask.invoke(SubversionSCM.java:867)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2348)
at hudson.remoting.UserRequest.perform(UserRequest.java:118)
at hudson.remoting.UserRequest.perform(UserRequest.java:48)
at hudson.remoting.Request$2.run(Request.java:326)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Finished: FAILURE
I had to remove the newer jar as well:
cd /var/lib/jenkins/plugins/subversion/WEB-INF/lib
mv svnkit-1.7.10-jenkins-1.jar /tmp
/etc/init.d/jenkins restart and it worked! Great Find!
Found the problem..
There was an old svnkit-1.3.6.1-jenkins-2.jar in C:\Program Files (x86)\Jenkins\plugins\subversion\WEB-INF\lib
Shutting down jenkins and deleting this file solved the issue.

javax.security.auth.login.LoginException: Login failed

I'm trying to run a hadoop job (version 18.3) on my windows machine but I get the following error:
Caused by: javax.security.auth.login.LoginException: Login failed: CreateProcess: bash -c groups error=2
at org.apache.hadoop.security.UnixUserGroupInformation.login(UnixUserGroupInformation.java:250)
at org.apache.hadoop.security.UnixUserGroupInformation.login(UnixUserGroupInformation.java:275)
at org.apache.hadoop.mapred.JobClient.configureCommandLineOptions(JobClient.java:557)
... 3 more
The same job works fine in an another windows machine. Do I have may be something wrong in the settings variabls? How can I fix this problem?
Maybe bash is not available on your PATH?
Do you have Cygwin installed correctly?
I really like this tutorial by Vlad Korolev to set up Hadoop on Windows.

Resources