简体   繁体   中英

Jenkins | "The system cannot find the file specified"

I am using Jenkins to schedule my selenium/java automated tests (test scripts packaged into a .jar file).

I have created a .bat file to trigger the .jar file and i am calling the .bat file from Jenkins.

When I manually trigger the tests, by double clicking on .bat file, everything runs smoothly. But when I try to run the same through Jenkins, I am getting the following error for each test case:

"The system cannot find the file specified"

Jenkins is calling the .bat file successfully, because I can see the test case name (which is present within .jar file) displayed on the jenkins console.

In my java code, I have used .\ to represent the "current directory" where my jar file is present along with an excel file which data drives the automation framework. Even the .bat file is present in the same location, and I have given fully qualified path on both .bat file and on jenkins.

I can't hardcode and will have to use ./ in my java code. And I am running this on Windows Server (not my local machine).

identify the current dir path where .bat file is placed and append / add to system path variable. Once done then allow jenkin to execute .bat file.

This is an issue with your working directory being different when you're running on Jenkins.

Easiest fix: Execute Windows Batch Command instead for your build step. On the first line, put cd C:/Desktop/QA/ to change your working directory to match what you're doing locally. On your second line use trigger.bat or C:\\Desktop\\QA\\trigger.bat .

More robust fix: In your java code, you're using .\\ when referencing other files. This basically means current directory, which won't be what you want if you're in a different working directory. Instead, you can look at this question/answer which shows how to reference the directory where your .jar file is instead of the working directory. In summary do this:

return new File(MyClass.class.getProtectionDomain().getCodeSource()
    .getLocation().toURI().getPath());

The problem was with the installation of Jenkins. A devops engineer solved this for me. Had to install Tomcat and jenkins within that. He said "If Jenkins is installed as UI, it can't open another UI. Hence we should install .war file on a separate server which creates separate UI for jenkins, and my application UI (firefox) can be launched on the local".

It seems while removing the files/folder or copy the files to remote server it may give below error message:

Caused: java.io.IOException: Cannot run program "nohup" (in directory "C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\Test_ssh_Remove"): CreateProcess error=2, The system cannot find the file specified
java.io.IOException: CreateProcess error=2, The system cannot find the file specified

To resolve this issue you must give relative path in source and target instead of absolute path as below. eg Here "Program Files" folder inside the C: drive on windows machine (Remote server).

Sample:

dir('VueAPP') { // Go to Your Current Directory where build code present to copy at Remote server 

   sshRemove remote: remote, path: "/Program Files/Apache24/htdocs/dist"

   sshPut remote: remote, from: 'dist', into: '/Program Files/Apache24/htdocs/'

   sshPut remote: remote, from: 'index.html', into: '/Program Files/Apache24/htdocs/'

}

For me, there was an extra space in the path of java "C:\Program Files\Java\jdk1.8.0_301/bin/java" I updated and it worked. Manage Jenkins -> GLobal Tool Configuration -> JDK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM