Copy an artifact from jenkins to another server with new name - java

I have a few jobs that automatically build a java app. I would like it to automatically push it to a other server. I found a plugin that copies artifacts over ssh, but using it I end up with app-1.0-SNAPHSHOT.jar, app-1.1-SNAPHSHOT.jar and so on on the remote server.
I would like to have it as app.jar instead, overwriting the old one every time. Is there a "intelligent" way of doing this, or should I just make a shell script that looks for the newest one, and overwrites it?

If you are using a Maven project I would recommend Mojo's Ship Maven Plugin for doing the transfer via your build scripts.
If you want to do this via Jenkins plugins, there are the following plugin options:
Publish via SSH
Publish to a FTP server
Publish to a Windows file share

I just do it right in my build scripts. Why all the extra management? In ant,
<copy todir="${remote}">
<globmapper from="*" to="app.jar"/>
...
</copy>
works perfectly fine.

Related

How to make maven install in docker container

I have a multi-module project on maven. It is quite ancient and is going with a special dance with a tambourine.
Project structure
root
|__api
|__build
|__flash
|__gwt
|__server
|__service
|__shared
|__target
|__toolset
To build such a project, I have a special script that needs to be executed while at the root of the project.
./build/build_and_deploy.sh
When building on Windows, there are a lot of problems (problems with long paths, symbols and line separators get lost, etc.), so I want to build this project in docker.
At first I wanted to connect docker-maven-plugin from io.fabric8 as a plugin in maven, but as I understand it, it cannot run the build of itself in docker.
So I tried to write Dockerfile and ran into the following problems
I don't want to copy the .m2 folder to docker, there are a lot of dependencies there, it will be quite a long time.
I don't want to copy the project sources inside the container
I couldn't run the script./build/build_and_deploy.sh
How I see the solution to this problem.
Create a dockerfile, connect maven and java8 to it, and bash
Using Volume to connect the sources and maven repository
Because I work through VPN and the script is deployed, you need to find a solution to the problem through it (proxy/port forwarding???)
If you have experience or examples of a similar script or competent advice, then I will be glad to hear it
You can perform the build with Maven inside Docker.
For that you basically trigger something like docker build ., and the rest is inside the Dockerfile.
Start off from a container that has Maven, such as maven.
Add your whole project structure
Run your build script
Save your build result
To save your build result, you might want to upload it to some repository, or store it in a mounted volume that is available after the container run as well. Alternatively copy it to the next stage if you use a multistage docker build.
If you want to prevent repeated downloads of the .m2 directory or have many other dependencies in there, also mount it as volume when running the container.

Jenkins Octopus Integration

I am using Jenkins as a CI tool and using Octopus to deploy my JAVA application. But when surfed, i could get solutions to deploy a .Net application using Octopack. But how to pack my JAVA Application and automatically deploy it into the Octopus server from my Jenkins instance?
You can pack it with NuGet (with the nuget pack command, documented here). That's essentially all that Octopack does. Create a .nuspec file, and in your <files> section, include the files you want with an empty target. For example, this will include all files in your package:
...
<files>
<file src="path/to/output/**" target="" />
</files>
...
You can then push it to your Octopus Deploy system using nuget push. Instructions are on your Octopus Deploy Package Library page.
Since Octopus 3.3 you can also package in tar and zip, in addition to NuGet.
You can configure the machine where you want your code to be deployed to as a deployment target. Listening Tentacles are the most oft-used ones.
Once your deployment target is configured, setup Octo.exe on your Jenkins server and use the script console in your Jenkins job to automatically deploy your package to the intended target using Octo.exe .
You can also write the code to a script on the Jenkins server and call that directly from the console in the Jenkins job. We do this in our setup because Octo.exe uses the API-KEY which we'd rather keep secret from the developers.
Note: Octopus Deploy is also currently working on native Java support. See this RFC.

Resolve/Download dependencies after deployment to remote server

I have a big war file over-sized due to lots of external dependencies & also I have internet connection speed issues because of which I don't want to keep the dependency jars in my war, so that I could reduce war size & do faster uploads of my updated wars from dev machine to remote server.
I would like the maven project to instead download the dependencies on the remote tomcat server itself when it has been uploaded there & starts running. How do I configure maven to do that ?
There is a pretty simple solution: Build the project on the server.
An easy way to do this is to put all the sources into a version control system like Mercurial or Git.
In addition to giving you a history and an automated backup, DVCS have insanely efficient algorithms to update remote copies (they just transfer the changes, so if you change a single line, only one line is sent over the wire).
Building on your server also means that you get the very fast download of dependencies on the server (which has probably very good download rates). And local deployment will be very, very fast.
Last but not least: When you use version control, you will be able to go back to the last stable version quickly when something goes wrong.
As Aarom says you should build the project on the server directly.
There are two requirements:
You need to have a command line access on the remote server.
Maven must be installed on the remote server.
Then you can upload the sources of your project on the remote server (without dependencies).
Go in the root directory of your project and run your build command (mvn package or whatever custom build command that you use).
So that's it, you have the .war on the remote server loaded with all the dependencies; you can then remove the source files.
#user01
Install all desired 3rd-party jars to Tomcat's lib folder.
Set the scope of those dependencies to "provided" in you Maven pom.xml.
Install Maven on your remote server.
Install a CI server such as Jenkins, Continuum, Bamboo, Hudson, CruiseControl, etc. I'd suggest Jenkins.
Hopefully, you are using revision control software such as SVN, Git, Mercurial, Bazaar, or CVS. If not, then I'd suggest setting up
Git or SVN for your source code repository.
Configure the scm tag in your pom.xml to point to your project's location within your source code repository.
Configure your CI server to get your pom.xml from your source code repository. Your CI server will read the scm tag, and the
URL's you've configured within the scm tag, and will check your
project out. Your CI server will then build your project.
You can either have Jenkins deploy your built war artifact to Tomcat via the Jenkins Deploy Plugin, or you can use a Maven plugin such as the
tomcat7-maven-plugin or Cargo.

Java build system options

I'm currently building a desktop java application in a very clumsy manner. The application is deployed on Windows, Mac and Linux. Here's my build process now:
On Windows:
Update local repository
Fire up Eclipse
Refresh the project
Double click the .jardesc file to generate an executable jar file
Commit the executable jar to source control
Open up the .nsi script and click the build button (I have NSSI plugin installed) to produce the .exe installer
Upload installer to ftp server to publish
On Mac:
Update local repository
Run shell script to generate .dmg file using .jar in source control
Upload to ftp server to publish
On Linux:
Update local repository
Run shell script to generate .deb file using .jar in source control
Upload to ftp server to publish
I'd also like to include some extra steps in my build in the future, such as:
Setting build date
Setting the HEAD git commit-id
Performing some code obfuscation
Any suggestions on how I can streamline and speed up this process?
If you are serious about having a good build system, then I'd recommend learning and using Maven, which provides:
Comprehensive project build lifecycle management based on a declarative project definition (pom.xml)
A huge range of plugins, which I expect will be able to handle all the specific build steps you require
Very good integration with Eclipse
Full dependency management (including automatic resolution and download of dependencies)
This is not for the faint hearted (Maven is a complex beast) but in the long run it is a great solution.
First step would be to just get everything building without Eclipse.
You might also want to consider using something like Jenkins to automate some of this. You'll still require build scripts.
A solution could look like
Update repository.
Jenkins detects update and builds the jar.
Jenkins saves the jar to some location.
Then you can have separate builds for each OS, also running in Jenkins. These could be triggered automatically on successful completion of the first build. These would each:
Pick up the jar from the previous build.
Publish the OS specific binary to an FTP site.
Ant is a good start, but you may also want to look at Apache Ivy or Maven, as these will help a bit with managing your build outputs and dependencies.
You should have a look at Ant: https://ant.apache.org/
Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications.
Also, a long list of build systems: https://en.wikipedia.org/wiki/List_of_build_automation_software

deploy java jar remotely during maven build

I have a small maven project that build a java jar file. I added a plugin (maven-antrun-plugin) in order to start it during maven's build phase. This also works in the build server (Continuum) which is good.
Now I would also like to copy the artifact jar to another server. What is the best way for doing that? I saw that you can make maven execute bash script, would that be a good way?
thanks!
It depends on your server and what options you have for uploading jars there. One of the options could be to use Maven Wagon plugin, which supports number of protocols, including ssh, ftp, webdaw.

Categories

Resources