How to configure Jenkins, running code from Local to slave machine? - java

I have a project in Java and I also used Gradle and TestNG. It works perfectly without jenkins.
After that I configured Jenkins and now I can run the code with Gradle command in Jenkins on my Local.
Then I tried to run the code on Slave machine. I can see the Slave machine in Jenkins nodes. I also configured Gradle and Java to run on Slave machine. I have to mention that I don't use Version Control in this project.
When I start the job in Jenkins to run on Slave machine, it starts the job but the problem is, it cannot find for example the gradle.build, as it's located in my Local machine and not in Slave machine.
The question is, should I use Version Control? is it going to solve the problem? or should I use Copy Artifact Plugin ?
Complementary Question: If I make a local git for my network on the same machine that runs Jenkins, it is going to be a problem?
Thanks for your help :)

Slave machine need your file gradle.build, so either place it there manually by SFTP.
If your gradle.build going to change regularly then its prefer to use version control like git by which jenkins will fetch the latest files.
Again its not mandatory but recommended to use version control like git to prevent from unnecessary errors

Related

Can't load main class JUnitStarter when running tests on remote host via SSH on Intellij

I'm wanting to run tests on another more powerful machine to speed up testing time, so I've created a run configuration on Intellij which targets my Ubuntu machine rather than my local one.
If I don't use rsync to copy the files to the remote target, the tests all work fine, however when I enable rsync in IntelliJ, I get the following exception when the tests attempt to start:
Error: Could not find or load main class com.intellij.rt.junit.JUnitStarter
Caused by: java.lang.ClassNotFoundException: com.intellij.rt.junit.JUnitStarter
Process finished with exit code 1
Although I could run without rsync enabled, the copy process to the remote host takes longer than running the tests on my local machine.
For context, my local machine is running Windows 10, and my remote machine is running Ubuntu 20.04.
Thanks in advance!
EDIT:
After doing a bit more digging, I found that rsync is copying files in the maven repository and Intellij Ultimate folder using the MS-DOS file structure style. This means that as part of the copy, it's using backslashes instead of forward slashes resulting in linux thinking it's part of the name of the .jar file. In result, it means that the copied maven repository folder is in the wrong file structure:
Changing the file structure manually fixed the issue and tests run successfully however it's just a work around and doesn't directly fix the problem but at least points in the right direction.
This is a bug: https://youtrack.jetbrains.com/issue/IDEA-270106
Will be helpful if you can vote for it and attach idea logs there

Developing Java (Maven) application on Docker container

For a new Spring project I'd like to setup a Docker container to build + run + debug my application.
At the moment I'm using this Dockerfile:
FROM maven:3.6.2-jdk-8-slim
COPY . /app/
WORKDIR /app/
RUN mvn clean package
FROM maven:3.6.2-jdk-8-slim
COPY target/app.jar app.jar
ENTRYPOINT ["java","-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-jar","/app.jar"]
EXPOSE 5005
In the first step the project is built. In the second step the application is run exposing a 5005 port for "remote" debugging.
Then from my IDE (IntelliJ IDEA) I'm configuring a remote debugging configuration to execute debug on the container.
As you may guess is a bit awkward to execute these steps for every little edit I'd like to debug in the project.
So, I'm wondering if there's a more practical approach using IntelliJ to automatically build and attach the debugger to my application just like when developing directly on my dev machine...
First of all, you can open a pom.xml right from IntelliJ and run the application without the need to run maven (IntelliJ has an excellent maven plugin).
Since you're running it as a java -jar you don't even need an ultimate version of IntelliJ.
Now this is how we develop usually, even before maven. You can run mvn clean package locally as well if you want to, say, check that the tests are run (again, you can also do that in Idea). And when you push your changes create a docker and deploy on server.
This is by far the best solution I can recommend. The way you've described in the question suites more to debugging the remote servers (read ready environments).
If you absolutely need this way, you still can use HotSwap feature of JVM for small changes (as longs as these changes are inside the method): While connected via Remote Debugger, right click and "Recompile" the class that has a change. It will be automatically loaded to remote JVM so that you don't actually need to trigger all this process.
You also don't have to run all the tests in maven (mvn clean package -Dmaven.tests.skip)
A couple of ideas that you can implement:
Use CI/CD to build your docker images
Instead of offloading this work to docker files, let your CI/CD pipeline to build your artifact and then pack it into a docker image ( you'll have more control over the process ). Finally, you can also deploy it to a targeted environment.
Use IntelliJ to run and debug your project on the DEV machine
You gain almost no benefit by running your project using Docker on your DEV machine, only a lot of hassle.

Maven tests pass in Windows 10 but fail in Ubuntu 16.04

I have a Spring Boot project which passes all it's tests under the mvn clean install command in Windows 10. The same exact code base, against the same database, has some test case failures when executing mvn clean install in Ubuntu 16.04. I traced the problem to a directory not being created by the code inside a failing test case using the mkdirs() function. I don't know why, I mean, I own the project so I wouldn't think it's a permissions issue. I cloned the project in Ubuntu from the remote repository using Intellij IDEA's built in Git functionality. Many of the other test cases (hundreds of them) are passing but a few fail and they are all related to this mkdirs() issue. Just to reiterate, the problem only exists in Ubuntu 16.04, not in Windows 10 where all tests pass. If more information is needed please let me know I'll provide.
Is there any way to resolve it without altering the code?
I found that the issue was a root directory setting being set in a configuration file of the code base. While that root directory would be openly accessible on a Windows platform, on Ubuntu it was restricted. Changing the setting in the configuration file to point to a base directory where I know I had write permission solved the issue.

Install java on linux server programmatically

I am trying to set up the environment with Java, git, Jenkins and maven by mentioning the IP address of linux VM. I have written a code to connect to VM, create folders, and move files to folders.
Now I want to install all Java and others software programmatically. Ib tried to install Java using yum -y install java-1.7.0. There is no error but then Java is not installed.
Please suggest what needs to be done so that Java gets installed and java_home path is set programmatically.
Any help is appreciated.
We've been doing this at the office this week. It sounds like you want a solution which would include JscH because you've started down that path. What I have to offer you is a solution that uses Jenkins.
We set up a target machine (two actually) as Jenkins slaves. It's rather easy to do, but you do need to install a JVM. You might look at docker.
Once the Jenkins slave is connected to the jenkins master, we just instruct it to run scripts. Some commands require sudo and so we set that up so that it does not require a password to be entered. Alternatively, you could run the jenkins slave jar after already having sudo -- not recommended.
We made a pom.xml to fetch .jar files and tar.gz files out of maven and copy them into a specific location. Then we executed scripts that manipulated them. The scripts came out of version control via Jenkins, but other files we pulled out of version control using a script.
All in all, I have the following tips for you:
Debug a script by executing it without Jenkins, and then run it under Jenkins for some final debug.
Put plenty of echo statements into your scripts so that you can see what has gone wrong.
You're totally relying on the Jenkins log and print debugging. This is very time consuming. So you would do well to pay attention to point #1.
Good luck :-)

running an ant build file on remote system

I have an build file located on a remote system. I want to run it there itself.It would be good if I can invoke it using a java program from my local system only.I tried using google but no success.Is it possible at all?
(extending comments on jenkins into answer)
I suggest Jenkins with master slave configuration to fully automate your build process. It comes with hundreds of plugin (You have plugins for static code analsys, test, test report, publishing , deployment.., supports many VCS).
Jenkins exposes operations via web-gui. It also has command line tool to aid in automation . You can easily add multiple machines into build and extend your workflow..
If your slaves are on windows, only trouble you have is an FAQ: https://wiki.jenkins-ci.org/display/JENKINS/Windows+slaves+fail+to+start+via+DCOM

Categories