Jenkins Get a file from workspace using Java - java

I have a job on Jenkins that compile an *.exe files .
Using "Copy To Slave Plugin", i manage to copy to job Workspace the files after compilation.
The URL is like that: job//ws/output/.
I want to use another job in a different slave that get this files and execute them there, this job is written in java (running with maven).
I couldn't find any Example of 'how to get file from jenkins master'.
There is anyone who knows how to Receive this files, or you have maybe other proposal how to inject the files directly from one slave to another (trigger by Jenkins of course).
Thanks a lot.

Related

Can we upload jar file in jenkins directly or we have to first upload jar file to git and add repo link in jenkins?

I need to execute a standalone jar file with command line parameters from jenkins. Can I upload the jar file directly to jenkins or I have to first upload the jar file to github and then give the repo link on jenkins to run it. Also, from that entire jar file, I just want one of the .java class or files to be run in jenkins so I will use the "execute shell" in jenkins to give the command to run, right? I am looking for the best approach. Also, If I want to provide password+some configurable variables used in my code as command line arguments , should I provide them as "parameters" in jenkins while configuring?
I am trying to find the best way from start to end to execute a jar file from jenkins .
there is no better option to upload JAR directly , either you can upload in any repo and access through the link ,else you can keep the jar file in the local workspace of the system where Jenkins is installed.
Also for the variables like password and other configuration either you can add them as a parameter or you can create a .properties file in the repo and store all your variables data and values in that. Before building the project inject environment properties and give the path of properties file.

Maven or Ant for autodeploy and run project on remote server

I have a question according to automate my project lifecycle.
Now i do this manualy:
build my project with Ant, get target jar, rename it manualy (add
suffix, like version2.0-myProject.jar);
connect to remote server via ssh, open FreeComander and copy jar
file and INI-properties files to different folders on remote server;
Remoutly run my application throws putty (exec bat file on server,
which contain all cmd run command. This .bat contain plink.exe remote command to Lunux server, whoes contain instance of app).
What i want to do:
i want to automation deployment procces, include build phase and app run phase,
i want to do this:
When buld executed, user asked for output-jar file suffux(like varian2-myapp.jar), ask user for properties file with what programm will execute later, and ask user for Allocated memory for JVM (now it is part of cmd comand in .bat file)
My app is simple, contains 15 Classes and 3 external libs. I want to make deployment easy and automate this process, i learn that Maven or Ant Build can help me. Please say, what way is more comfort for my task of using this build systems.
With Maven you can use the Maven Release Plugin to deploy your package (which could be a zip with your jar and other dependencies for example) to a Maven repository (which you could be running in one of your server).
This page should get you started:
http://maven.apache.org/maven-release/maven-release-plugin/
With Ant, you can use Apache Ivy instead:
http://ant.apache.org/ivy/history/2.2.0/index.html
You then need a way to tell the server serving your app to pull the package and start using it (install it).
You could write a simple script that pulls the repo, which you trigger remotely, maybe using
plink -m
as you are doing now, or use one pre-built automation software, like https://puppet.com/.

how to deliver QA Automation code?

I am having a QA Automation framework for an web application using selenium and java,testng in Eclipse as a maven project.
I am using cvs for code versioning among the team.
I need to deliver the updated latest code to the manual testing team for usage. They just change the testdata, and execute the corresponding scripts using the .xml files(Test files are kept in xml files).
Is there a way/tools which hides my code from them?
Compile your code and export as a jar file, which contains only the .class files
Create a batch file, which executes your driver script as required
Yes you can do this,
Use a batch file to run your program
Create a txt file and copy below code:-
java -cp ./ws.jars/*;./bin org.testng.TestNG testng.xml
In above code ws.jars is a folder which contain all jars which is being used in your project.
Now rename the txt file and change it's extention as .bat.
after click on it bat will run classes according to your testng.xml file.
You can also delete the src folder as TestNG need only bin means class folder.
While I am afraid you can't do same with maven as maven use src/test folder for execution.
Hope it will help you :)
It sounds like you should possibly set up a build server such as Jenkins. This will allow you to link your CVS to Jenkins. It will also allow you to let the manual testers pass in any parameters via the Jenkins GUI.
This will keep your code hidden (within reason) although hiding code from the QA team doesn't seem like the best approach. If you are the person in charge of the Jenkins server, it will also allow you control of who has access to the server and also who can execute and run the tests.

Running a compiled Jar file in Jenkins

I am trying to run an executable jar file through jenkins. What I am trying to achieve here is I have an executable jar file created and is residing locally in my machine. I want to put it in Git and then run it in jenkins. Is there some how I can do this? I am totally new to Jenkins and if someone can help it will save me a lot of time.
You can do nearly everything you want with Jenkins since you can have it run arbitrary scripts / executables.
If you want to put this .jar in git, then the Jenkins jobs will retrieve it when it fetches the repo. Then you just need to add a script shell step to the build, and to put your command line java my.jar my.class ....
On the other hand, it's sometimes frowned up to put binary files in git. It's true in particular if the .jar will need to be often updated. Hence you might want to provide the .jar to the Jenkins job using alternative methods. For example using a maven repository.

Jenkins and Maven : how to package some files in my JAR and unpack them before running a test?

Using Jenkins to run my test suite. As part of the setup for an integration test, I need to copy a bunch of files into a given folder. I'd like to include these files in src/test/resources, and then somehow unpack them and copy them onto the folder before running the test. What's the best way to accomplish what I'm trying to do?
Edited to add :
Basically, I'm testing a method that needs to read some files from a folder on our hadoop cluster. On my Jenkins box, I have a single-node hadoop "cluster" running in pseudo-distributed mode. Thus, I need to copy those files onto the cluster before running the test. So I need to :
A) Somehow get the files onto the Jenkins box (I was thinking it would be easiest to package them in the JAR) and
B) Copy those files onto the hadoop "cluster".
First thing you should do is to set the option in jenkins job so that your workspace is not cleaned up on every run. This will esure that folder structure is intact before you start the build.
Use the plugin https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep
You can add a step before you start the build copying and unpacking [basically it will provide you unix shell to execute any commands, so its you can do anything like ftp,rsync, unjar here].
But i am not sure how will you direct your test case to use these new files, but then i have never worked on hadoop so can't comment on that.

Categories