Jenkins built automation
On this page, we can see how a built happen automatically when there is a change in the code.
Log in to the Jenkins server and select the job which we built recently.
Click on Configure from the left side panel to make changes to the job definition.
on the next page, under the “Build Triggers” tick “Poll SCM” (periodically polls the SCM to check whether changes were made) and schedule the cronjob to run every minute. You can set any time, for the demonstration I set it to run every minute (5 starts).
Click Apply and Save button to save the changes.
Next, I will make changes to my code which is present on the Github repository. I will make these changes directly from the Github website.
I have modified the code as follows in the index.jsp file. To modify the code click on pencil icon present in the code editor tab.
Once you completed the edit, commit the code changes ( commit button is at the bottom of the page) and wait for 1 minute to start the build automatically.
Check the build history panel and you can see the build has started (here the number is #5). Check the console for complete output. My build is successfully completed so I got the below message.
[JENKINS] Archiving /var/lib/jenkins/workspace/war-deploy-tomcat/pom.xml to com.example.maven-project/maven-project/1.0-SNAPSHOT/maven-project-1.0-SNAPSHOT.pom channel stopped [DeployPublisher][INFO] Attempting to deploy 1 war file(s) [DeployPublisher][INFO] Deploying /var/lib/jenkins/workspace/war-deploy-tomcat/webapp/target/webapp.war to container Tomcat 8.x Remote with context null Redeploying [/var/lib/jenkins/workspace/war-deploy-tomcat/webapp/target/webapp.war] Undeploying [/var/lib/jenkins/workspace/war-deploy-tomcat/webapp/target/webapp.war] Deploying [/var/lib/jenkins/workspace/war-deploy-tomcat/webapp/target/webapp.war] Finished: SUCCESS
From the output message, it is clear that the war file deployed to the same “webapp” folder.
Go back to the browser and refresh the application page. You should see the updated application.
Here, we have learned the automatic build and deployment of the application with the help of Jenkins software.