How to deploy my Spring Boot project on Jenkins? - maven

I am trying to create a deploy job in Jenkins for my Spring Boot - Maven project. These are the steps i have followed until now:
Click New Item
Give a name, and choose Maven project
Configuration page opens
In Source Code Management, i have given my Git repository URL
In Build section under Goals and options i have written "spring-boot:run"
Saved and applied
Now when i click "Build Now", it checks out the project, builds and deploys. But the job does not end. This is the last line in the console output screen:
: Started Application in 4.737 seconds (JVM running for 16.297)
What is my problem? I need a simple step by step guidance since i do not have any Jenkins experience.
EDIT: I do not know what post build action is which is mentioned in the other post. I need a simple step by step guidance since i do not have any Jenkins experience.

The job doesn't end because your application is up and running on embeeded Tomcat. It's normal behaviour and you should be able to use your application at this point.
If you want to make another build, you should stop current build before starting a new one. To do this automaticaly (e.g. when your master branch is changed) you can create another one job.
Example of a job that triggers build of a main job:
Create a 'Freestyle project' in Jenkins;
Fill 'Source Code Management': your Repository URL and Credentials, Branches to build - */master;
Fill 'Build Triggers': select 'Poll SCM' and type H/2 * * * * in 'Shedule' to poll repository every 2 minutes;
Fill 'Build': add build step 'Execute shell' and type next commands to stop current build and start a new one (don't forget to replace JENKINS_URL and JOB_NAME with your values) -
curl -X POST http://JENKINS_URL/job/JOB_NAME/lastBuild/stop;
curl -X POST http://JENKINS_URL/job/JOB_NAME/build;
Save your job :)

I think that if you are going to deploy the spring-boot application in another server different to jenkins server you need to build your app mvn clean package and to move the jar created from jenkins server to the new server then you can use another step to start the app using java -jar myapp.jar. But, if you are going to deploy in tomcat server then you can use tomcat-api to deploy remotely.

Related

Q: Can I trigger a Jenkins job from a Maven plugin?

The setup is as follows:
Step 1: I am developing on a windows 10 machine
Step 2: Building artifacts with Maven (using powershell)
Step 3: Go to (semi-local) Jenkins which is running in a Linux VM on my machine & trigger a Jenkins job that syncs and deploys my artifacts to the application server running on the VM.
Q: Is it possible to automate/merge Steps 2 and 3 in this scenario?
(Building and deploying each takes several minutes)
Yes, you can.
Create a custom goal which will trigger the Jenkins with an URL.
But, ideally, I would suggest to build and deploy using Jenkins by fetching the code from the repository when there is a change
Yes you can.
I suggest you use webhooks (github, gitlab, bitbucket,...)
Steps will be :
Install some plugin in your jenkins in order to expose a job as public url.
Configure your webhook in git provider adding url created in step 1
Push some changes to your code
Your git provider detect this event and execute the url created in step 1
Your jenkins job is launched. Put your mvn commands and deploy commands in this job. I suggest you use jenkins pipeline job.
Contact me if you need some help.
Post step by step :
https://jrichardsz.github.io/devops/devops-with-git-and-jenkins-using-webhooks

Where does Jenkins store the project source

I have a Jenkins job that uses a script to build my project. On the following line, the script fails mvn -e -X -Dgit='$git' release:prepare.
Because I want to search for the cause of this, I want to go to the Jenkins server and run mvn -e -X -Dgit='$git' release:prepare from the command line, to see if it works.
Does Jenkins store the projects' source code somewhere, such that I can go to that folder and call Maven?
If yes, then where?
Yes, It Stores the project files for the job by default at
/var/lib/jenkins/workspace/{your-job-name}
This is where jenkins suppose the project files to be present or it pulls it from a source before start working/building from it.
Quote from Andrew M.:
"Hudson/Jenkins doesn't quite work that way. It stores configurations and job information in /var/lib/jenkins by default (if you're using the .deb package). If you want to setup persistence for a specific application, that's something you'll want to handle yourself - Hudson is a continuous integration server, not a test framework.
Check out the Wiki article on Continuous Integration for an overview of what to expect."
From this Question on serverfault.
This worked for me:
/var/jenkins/workspace/JobNameExample
but, if your build machine (node) is a different than the one where Jenkins is running (manager), You need specify it:
/var/jenkins/workspace/JobNameExample/label/NodeName
Where you can define label too:
jenkins stores its workspace files currently in /var/jenkins_home/workspace/project_name
I am running from docker though!

Jenkins Websphere Deployment doesnt retain application configurations

I am using Jenkins version 1.644 and trying to deploy a web application to Websphere 8.5 application server. Jenkins job completed successfully and application is visible through admin console. After the first install, i manually configured Three application configurations namely,
1. Virtual Host
2. Context Root and
3 Modules
after these setup application comes up fine.
Now when i run the Jenkins Job again (option used is Install/Update application), it overrides all the configurations.
Please Let me know how to keep the configurations after each build from Jenkins.
Websphere Plugin Configuration
You can create a build deploy job which will call wsadmin tool and there you can pass parameter in key value pairs
Here is an article which talks about how to build job with parameterized configuration.
http://www.touchdownconsulting.nl/2011/03/building-and-deploying-websphere-applications-with-jenkins-ci/
I have not tried this but looks like it suits your requirement.
Hope this helps!
Current Jenkins Websphere deploy plugin (1.3.4) version does not allow to pass
1. Virtual Host
2. Context Root and
3. Modules
I created a Jython script using AdminApp WAS Utility and updated these parameters
AdminApp.edit("appname", ['-MapWebModToVH', [["appname", "appname.war,WEB-INF/web.xml", "api_host"]]])
AdminApp.edit("appname", ['-CtxRootForWebMod', [["appname", "appname.war,WEB-INF/web.xml", "/appname"]]])
AdminApp.edit("appname",['-MapModulesToServers', [["appname","appname.war,WEB-INF/web.xml","WebSphere:cell=appcell01,node=node12v,server=web2+WebSphere:cell=Cell01,node=node11v,server=web1+WebSphere:cell=Cell01,cluster=api-cluster"]]])
AdminConfig.save()
Used Jenkins Remote SSH Plugin to invoke this script.

Create job in jenkins with calling svn and maven

For now I have a batch file with commands for update projects using svn and calling maven 'clean install'. How to create some job in Jenkins for similar actions?
Should I write it to ant file (sorry if it's stupid idea, I've just heard about it but I don't know what is it exactly and what can I do with this) or there is other way?
Thanks
Like arghtype suggested, you need to be using Jenkin's own Source Code Management by configuring SVN as SCM source and supplying credentials as part of Maven build job.
If you have to use your own local working copy, you are organizing it wrong, you will lose on all the benefits of having Jenkins manage SVN changes, and in the end, this organization will give you more unsolvable problems in the future. Think about the advice people are giving here and come with up a reason why you need to have a local workspace outside of Jenkins management on a Jenkins build machine. My only guess is: your Jenkins and Development machine are the same. That again is not how it should be organized. Jenkins is a CI-server, not a personal build "automator".
Regardless, if you still want to do what you say.
What you think you want
Create a new Freestyle job
Under Build Steps, click Add build step
Select Execute Windows batch command
Write your batch execute command in there. Your working directory will be Jenkins's $WORKSPACE, so change your path accordingly to where you want to run it.
But with the above configuration, you might have as well put the batch file under windows scheduler... You are not really using Jenkins with the above.
What you should do instead
Create a new maven2/3 build job
Under Source Code Management, select Subversion
Under Repository URL enter the remote SVN repo (i.e. http://your.svnsever.com/path/to/project)
Under Build, enter your Root POM location (this will be relative to the location of your SVN checkout, so if your POM is under http://your.svnserver.com/path/to/project/maven/pom.xml, then enter maven/pom.xml.
Under Goals and options, enter clean install
Click Save
The Source Code Management section will take care of setting up a local workspace and checkout the repository into that workspace. By default, every time a new build is triggered, it will run svn update on that workspace for you.
The Maven Build step will take care of running your Maven, however note that it is configured to use default ~/.m2/repository location. If your local maven repo needs to be different, change this under Jenkins Global Configuration
Create a new job.
In Source Management choose Subversion, specify your repo and credentials.
Add a new build step - maven build, specify your maven goals ('clean install').
Jenkins is a CI(contiounus integration) server. It can be used to generate scheduled builds of ant or maven based projects. It can also start building projects by some triggering event such as a commit to SCM (git, svn, mercurial,...)connected to it. You really have to read its documentation to get a better understanding. It has nice tutorials.

Setting an Endpoint in Jenkins

I currently have a SoapUI project which I intend to have executed periodically (every 5 minutes) in Jenkins. I've completed the following thus far:
Created the relevant directory in the Workspace i.e workspace\SOA\SOAProject\src\test\soapui\SoapUIProject.xml
I've configured a pom.xml which sits in the SOAProject folder alongside the src folder
I've created a Jenkins job (I've chosen a Maven project, although it should not be an issue if I had chosen a freestyle job)
My question is, how do I set the endpoint?
I've done the following...
Build
**Root POM** pom.xml
Goals and options
testrunner.bat -e0.00.0.006:8040
Edit:
I've installed the EnvInject plugin. I'm not sure how to create the /properties file and what to put in their in order to set the execution environment?
I don't know the answer, but my suggestion is to get it running via command-line first. Once you figure out how to launch it without Jenkins, having Jenkins issue the same command because easy.
If you choose a Maven project, there is a useful plugin to set the endpoint and different propeties for the testSuites...
https://github.com/redfish4ktc/maven-soapui-extension-plugin

Resources