I have an application that takes the changes and pushes on git. Now i want to create a deploy button on my application, clicking on which, will automatically trigger "Build Now" on Jenkins and display the console output on my application. (I am already storing the userid and password for jenkins within my application.) This will enable me to do everything within my application, from creating the changes, pushing to git and finally deploying it on jenkins and seeing the console output without actually going to jenkins and doing it manually.
More info:My application is built in Spring boot and thymeleaf as frontend.
Thanks in advance.
You can use Jenkins CLI
The command line interface can be accessed over SSH or with the Jenkins CLI client, a .jar file distributed with Jenkins.
with build command
One of the most common and useful CLI commands is build, which allows the user to trigger any job or Pipeline for which they have permission.
Jenkins also has a REST api that you can use, use POsT to trigger and GET for the reults
https://wiki.jenkins.io/plugins/servlet/mobile?contentId=753720#content/view/753720
Related
I have been given the task of developing code that generates an email when a user deploys new code to our servers. I already have the code to generate the email. However Im trying to run this code when we add new code to our servers. We currently deploy new code to our servers using the MAVEN Deploy command in Eclipse. I was wondering if there is a way to run a java main method or something along those lines when a user selects Maven Deploy in Eclipse?
Not sure of your actual use case or if this is the best approach, but you can run java programs using the maven exec plugin. See here for more details: http://www.mojohaus.org/exec-maven-plugin/examples/example-exec-for-java-programs.html
Im following the tutorial on the App Engine website for 'Google Cloud Endpoints' in Java. Everything works fine and I can run the development server using mvn appengine:devserver. The problem is that when I make any changes to a file (for example, any java file) the dev server doesnt automatically recompile. I need to ctrl-c to kill the dev server and restart it for every code change I make.
Is there a way to have maven automatically detect changes to any files in my project and have it automatically rebuild and restart the dev server?
Unfortunately no. If you want this behavior on your dev server, you need to use Python.
I run in the same issue and there is no real workaround provided by the App Engine to help you doing this.
From the "Using The Google plugin for Eclipse":
With Eclipse, you can leave the server running in the debugger while you make changes to source code, JSPs, static files and appengine-web.xml. When you save changes to source code, Eclipse compiles the class automatically, then attempts to insert it into the running web server dynamically. In most cases, you can simply reload the page in your browser to test the new version of the code. Changes to JSPs, static files and appengine-web.xml are recognized by the development server automatically, and also take effect without restarting the server. If you change web.xml or other configuration files, you must stop and start the server for the changes to take effect.
(https://developers.google.com/appengine/docs/java/tools/eclipse#Running_the_Project)
There is NOTHING comparable in Java (link from "The Java Development Server") (https://developers.google.com/appengine/docs/java/tools/devserver)
There's currently nothing in the App Engine SDK to automatically restart when files change, but that's not to say you can't do it. I ran into the same problem and wrote up a script to listen for file changes as triggers to restart App Engine. It's in JavaScript, so you'll need to install Node.js if you haven't already.
// Install watch-exec
$ npm install -g watch-exec
// Watch the current directory
$ watch-exec --command "mvn appengine:devserver" --watch .
This will immediately start App Engine, and then restart it any time a file changes. If the app crashes for some reason, the script will wait for your next edit before trying to restart.
P.S. That entire script is about 40 lines of code, and you could probably do the same thing in other scripting languages. If you haven't tried writing your own automation before, I'd definitely recommend checking out the source code to see how this works.
I've found using Gradle, GAE, and Spring MVC, the assemble command will put the correct artifacts in place, and the server will re-init the app. It's a little quicker than a server restart.
Using App Engine standard with the cloud.tools appengine-maven-plugin hot swap works fine (most of the time, can be problems when setting up the workspace).
For a multi-module maven project: no need to stop the server or browser,
just push the code changes (maven command package -pl *-server)
& refresh the browser.
Debugging with a debug client currently works perfectly for changing / adding code within methods.
I am following this tutorial:
https://spring.io/guides/gs/rest-service/
After completing the tutorial I run everything in my web browser on my local host and everything seems to work.However when I make changes in the java code (I made errors on purpose) I can still run everything in the web browser. What do I need to do in order for it to change due to my code changes? I guess I should mention that I am using eclipse and have installed maven as a plugin.
You are changing the source code, but not the compiled files. Your service is using the created "gs-rest-service-0.1.0.jar" file. This is not affected by your code changes.
Jump into the tutorial again where it says:
"Build an executable JAR"
This will rebuild your jar file. Afterwards you will have to restart your service like you did in the chapter "Run the service".
Instead of using maven as a plugin a choose to install it in order to use the command prompt.
I have a Spring Batch application with a Task Scheduler based on this implementation.
Basically, during development in Eclipse, I execute the following maven goal:
mvn clean install exec:java
to execute the batch application. The above command executes my MainApp class which has a static main class that loads the Application context file and from there, Spring takes control. During development, this is not a problem since I need to see the logs in the console. But during integration in my Jenkins server I am encountering a problem with this setup.
In Jenkins, when I try to build the application using the above goal, the build never finishes because it holds on to the console. I need the build to finish so that the downstream projects are also built. My question is, how do I tell Jenkins to ignore the console and proceed to the next build process? In short I want to start the batch application on the background without it holding on to the console so that my build can continue.
What I have tried so far:
I tried changing the goals such that exec:java will be called as a Post Step. Still it does not work. What are other methods in which to perform this?
I'm currently writing a GWT application through Eclipse. Eclipse is used for development but I use the m2eclipse plugin and a Maven pom.xml with the GWT plugin to build & run it.
When I need to debug the app I must:
Invoke "Run As ..." on a Maven project (via m2eclipse) "war:exploded gwt:debug". This launches GWT's app server and waits for a remote debug connection on port 3408. The need to wait for the WAR to be exploded means it could be a minute for this to happen.
Invoke "Debug As..." a Remote Java Application to connect to the server.
I've already added both targets to favourites to lock them into the drop down but it's still a pain.
I'd like to launch them both in sequence from a single click rather than two discrete actions.
Is there any way in Eclipse to achieve this?
Try this plugin. http://marketplace.eclipse.org/content/escripts
You can define scripts of Eclipse actions easily. You create a script of starting the 2 debug session, then run with one click or shortcut.
EDIT:
The plugin was moved and is now called EASE.
https://eclipse.org/ease/
"Launch Groups" are part of the CDT. Officially supported, easy to install.
See https://stackoverflow.com/a/11905444/518491
Why are you launching like this? Can't you just launch it by GWT plugin? Go to Run Configurations -> Web Application (the blue circle with "g" inside) and create new Run Configuration.
In it, in Main tab, enter (or select) your project, and enter com.google.gwt.dev.DevMode in Main class.
In Arguments enter -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -logLevel INFO -port 8888 -war path_to_your_dir_with_WEB-INF_directory com.package.your.Module