Jenkins & Java : How to specify input file location - java

I have a java project which compares data in two excel files and displays the output. IN my eclipse project i created a folder data and in the code I wrote code read from root/data and it works fine as well. But my manager asked me to move this job to Jenkins. So my question is how do i specify the input folder path in Jenkins , Should it be the same server where Jenkins is installed or Jenkins can read data from another location in another server ?

By default, Jenkins will work on the Job's workspace location, if you provide a path in the job (be it via Parameter or Env. variable etc), it will be relative to that location.
However, you can specify an absolute path for anywhere on the Jenkins Server, which will also work.
If you wish to read data from another server, you will need to make it available to the job's runtime/access level.
One example would be to put this file on IIS or Network Share or other form of sharing, and download it during your chef job into the workspace.
Powershell example for downloading a file from IIS site:
$source = "http://my-web-server-ip/download/mycsvfile.csv"
$destination = "c:\my-jenkins-job-workspace\mycsvfile.csv"
Invoke-WebRequest $source -OutFile $destination
Please consider the above is just a basic implementation of this, and this can be accomplish in a number of ways - which some may be better than others.

Related

How to 'docker plugin install' for json-based plugin

I'm working on a brand new volume plugin and I'm required all of vol-test tests to be passed. And I have all tests successfully passed (on an environment with installed plugin) except the first one, which is docker plugin install. The thing is that there are three possible ways one can install a custom plugin:
.sock files are UNIX domain sockets.
.spec files are text files containing a URL, such as unix:///other.sock or tcp://localhost:8080.
.json files are text files containing a full json specification for
the plugin.
and we use json, which is simply a REST server implementing docker API (written in java, spring). The installation process for it straight forward: just copy the json file in /etc/docker/plugins and dockerd automatically discovers it.
The problem comes when I try to integrate the plugin into docker plugin install command. As it stated here:
Docker looks first for the plugin on your Docker host. If the plugin does not exist locally, then the plugin is pulled from the registry.
Our installation process doesn't assume a connection to a private or public registry, so we need first docker plugin create command in order to create the plugin locally. And this is where I'm having hard time to wrap my head around how to do that with json-based plugin. As per this doc, I need to specify a path to the plugin. If I use a directory name it expects config.json and rootfs to be present in the directory.
BUT
1. config.json - this is a config, that describes .sock format configs, and not the .json format (please correct me if I'm wrong)
2. how do I create the rootfs and why do I need it if my plugin is just a standalone REST service and it is not even in the container?
Appreciate any help.
config.json - this is a config, that describes .sock format configs, and not the .json format (please correct me if I'm wrong)
I've verified it working with .spec files, not very sure how it works with json files though. For .spec files, you don't mention .spec files in config.json. That is used only for unix socket plugins (option 1). Infact there is no need to have config.json for TCP socket plugins.
how do I create the rootfs and why do I need it if my plugin is just a standalone REST service and it is not even in the container?
In my understanding, rootfs is only for unix socket plugins. Plugin discovery works out of the box if .spec files exists in the right folder. In nutshell, you just create spec file and put it in the right discovery folder and try to bootstrap the container with that plugin name. You don't have to run commands like "docker plugin create/install/enable". You run the server, put the file in right folder and let new containers use that plugin.

Saving an install directory for software

I have a software tool that I am working on in Java. It will be deployed to both Windows and Linux. I am at the phase where I am trying to determine the best course of action for saving the user's installation directory (where i will store all external files). Ideally I want the user to be able to move the program to any directory they choose (even after installation) and it will still be able to find the installation directory.
I have considered using environment variables to save the path but I am not sure if that is the best practice.
What is the standard practice for saving a path to an installation directory on Linux and Windows? (I am open to making different install logic for each OS)
Edit
After a bit more research, I have found that the /etc folder for linux is where I should store data and the Registry for windows. Can anyone confirm this?
In Windows, registry works great. Here's an example from a product I use (evo5.0 with eurovoiceHMP):
Locations of config and logging folders can be configured manually via the registry,
eurovoiceHMP and evo5.0 then "find" these folders under registry:
HKLM/Software/eurovoice
Specific registry setting examples:
HKLM/Software/eurovoice/HMP:
evoHMPLicencePath C:\ProgramData\eurovoice\HMP\Config\Licences.txt
InstallPath E:\hmpTest
HKLM/Software/eurovoice/evo50:
evo50SystemVoiceFilesDir C:\TeleSage\sysvox
InstallPath C:\Program Files\evo5.0
evo50LogDir C:\TeleSage\Logs

How can I resolve Windows vs Linux properties file paths?

I have a java project on a Windows box which builds successfully and all tests pass locally. This project is then checked in and built with Jenkins on a Linux box.
The problem I am having is related to path issues in my properties file which is used for running tests. I point to a resources dir for part of a file path like this: "./src/test/resources".
I am trying to access two files which reside in the same directory. File1 is accessed successfully. Then File2 access is attempted, but it returns a file not found exception.
I've tried using an absolute path like this: "/code/myproject/main/src/test/resources/..." This again works on my local box, but not on Jenkins because Jenkins only knows about" "/myproject/main/src/test/resources/..."
How can this be resolved?
Today I learned Linux is case sensitive. The file name extension is upper case, but I was pointing to a lower case one.
Depending on your version of Windows... Windows 7 (don't know since when this was implemented) understand linux-style / separator just fine, as long as the whole path is relative.

Avoiding hardcoding of Property File path specification

I'm having a small problem decoupling the path specification for properties files that my JAVA program uses , from the implementation itself.
The program may be deployed at multiple locations with different directory structures and I don't want the path specification to be hard coded into the Program code.
Here is the situation as it exists now.
I have one folder server/
Inside which there are 2 packages core/ & support/ (both of which have many subpackages underneath)
What I had done earlier was that , wherever the path for a properties file needed to be specified , I just gave a relative path i.e. properties/
In this scenario, the properties file needs to be wherever you're launching the program from. This worked during testing , when i was manually starting the program up using
"java ". and i would put the properties folder wherever I was starting the program from.
But in a real scenario, this program will be autostarted by a script (ksh) which is executed at scheduled intervals by a job.
In this case , giving the relative path doesn't work. I tried putting the properties files in the folder where the scripts are located , but that doesn't work either.
Right now , I am having to manually specify the path for each environment recompile the code and deploy a separate copy for each environment.
Is there any way to remove this coupling and just have one location for the properties file regardless of where it needs to be deployed?
use a System.Properties entry to specify the path, then on command line add it via
java -DmyProp=somepath -cp yourclasspath YourClass
In your app, you can retrieve it with System.getProperty("myProp"), just be sure to add proper testing and handle the Property Not Found scenario.
Another practice is to leave props in a jar and then load 'em with the LoadResource, in this way you just need to deploy different config jars in each deployment, but I think that the System.setProperty way is the fastest.
Generally some clients may not prefer to use -D= while starting your application. In fact you should also provide a .sh/.bat script file along with your jar file so that client can just double click on the script to run your application.
In this script you can have variable declared which you can ask the client to be configure accordingly. Client can just open the script file in text editor and type in the path of the configuration file.
Other way to use this script file would be to do following :
1) Check if YOUR_APP_NAME_CONFIG variable is set in system environment. If yes then go to step 3 or got to step 2
2) Ask the user on command line for the location of configuration file. Check if the location is correct. If correct then set the environment variable YOUR_APP_NAME_CONFIG with value of location of configuration file.
3)Start your application
Having a script file for your application gives you lots of liberty to do many stuff around automating the environment configuration for your application.
In your application get the config file path by System.getProperty("YOUR_APP_NAME_CONFIG").
This all may look like lot of pain but think from client perspective. Its cake walk for client that he just double click a script to start your application and for the first launch of application the script asks for some inputs if needed and then your application is good to go :)
What I did was pass another classpath parameter with the jar invocation..
java -cp classpath1;folder-where-propertiesfile-located Application.jar
and in the application use getClass().getClassLoader().getResourcesAsStream("properties-file");
This will automatically fetch the properties file form the appropriate classpath folder..
With this setup, I could change the properties file inside the folder and use the same jar file without re-archiving the jar..

Permissions for Java application on Ubuntu

I have a NetBeans RCP application that's currently working on Windows and I'm trying to make Linux compatible. The application creates folders and files and modify files as well.
It works fine on Windows without any modification but on Ubuntu it fails creating folders during start up. I know it's a permission issue.
What are my options?
Can the application itself assign the permissions it needs like by running a script using ProcessBuilder?
Thanks in advance!
It all depends on who you are when running the process on Ubuntu, and the path of the folders that you're trying to create. Does this user have permissions to create the folders in that directory? What sort of data are you writing out to disk? Can you use a platform neutral mechanism thats user oriented, like Java Preferences or perhaps:
System.getProperty("user.home")
-or-
System.getProperty("java.io.tmpdir")?
You either need to create required folders as part of a setup process or restrict your IO to folders you have access to (the users home and the temp folder). Notice that on Linux there are standard locations where many folders should be placed and that administrators will frown upon applications that do not follow these standards.
Can you tell what files/folders you need for what purpose?
Looks like the cause of the problem is the difference in path delimiter between Windows and Linux. On linux you should use normal slashes. The error mentions the path:
/home/javier\marauroa.trace.db
As the \ is not a path delimiter but the escape character it is trying to create a file in the folder /home where it does not have permissions.
The path should be:
/home/javier/marauroa.trace.db
You might want to consider putting your apps files in a subfolder called .yourappname so then it would become
/home/javier/.yourappname/marauroa.trace.db
This is what many unix applications do and hide it in normal file listings. To get the path seperator for the system your application is running on you can use the following static field:
java.io.File.seperator

Categories

Resources