Home java Setting up and integrating Jenkins and Gradle from scratch

Setting up and integrating Jenkins and Gradle from scratch

Author

Date

Category

There are many tutorials, but each covers only part of the process, I cannot find a simple and understandable for a beginner, covering the whole process.

What I want:

  1. There is a Java application (moreover, it can be a web application launched in the same Tomcat, or a regular console application or a library built in jar)

  2. Unit and integration tests written

  3. The application is built by gradle.

  4. Deployed Artifactory with repository where I want to deploy assemblies.

The actual process that I want to customize:

  • With each push, unit tests, integration tests are run on the server, code coverage by tests, codestyle, etc. are analyzed.

  • If all is well, the build is deployed to Artifactory, and (if the application is web), updated and restarted on the dev server.

  • Or have some page, which is a table: download link – commit message (for example: http: / /abrok.eu/stockfish/ )

  • If something went wrong, a response with a description comes to the mail (for example)

It would be great to watch a tutorial from scratch, when a helloWorld Java project is created, how Jenkins is configured, what happens when a commit is made, etc. Those. a tutorial where java code is written and changed simultaneously with Jenkins configuration.

Maybe not necessarily the process I fully described, but some tutorial that shows in a simplified way the development process (change, writing tests, commits) java application while jenkins is running.


Answer 1, authority 100%

If you focus on organizing the build process using Jenkins, you get something like this:

With each push, unit tests, integration tests are run on the server, code coverage by tests, codestyle, etc. is analyzed

A build trigger “Poll SCM for changes” and a schedule for checking Git for fresh commits, for example every 10 minutes, are set for the project (job). The schedule is set in the crontab format: H / 10 * * * * .

Another option is to select the trigger “Trigger builds remotely (e.g., from scripts)” and set up a post-commit hook in the repository that will notify Jenkins when new commits are available. To do this, simply pull the curl address http: // & lt; jenkins_server & gt; / job / & lt; job_name & gt; / build .

Test run is done by calling gradle. Install Gradle Plugin on the build server and call gradle as the main build step like if you were running it on your local machine. If the build will include a test run, jenkins will keep track of the results.

If all is well, the build is deployed to Artifactory, and (if the application is web), updated and restarted on the dev server.

Put Artifactory Plugin and add a post-build step “Deploy artifacts to Artifactory “.

It is better to redeploy the application into a separate project, which will be called after the main build through Post-build operation “Build other project” . To “reach” the main assembly artifacts from the deployment project, install Copy Artifacts Plugin . You will have access to the “Copy artifacts from another project” build step, which will copy the required files from the upstream build.

The deployment procedure itself can be implemented using Jenkins (for example, Deploy Plugin ), gradle tools (for example, gradle-cargo-plugin ) or just a shell script.

If something went wrong, the answer with the description comes to the mail (for example)

This Jenkins can “out of the box”, it is enough to include in the settings of the Checkbox E-Mail Notification “. But I recommend putting email-ext plugin – it allows you to flexible Events for writing and content.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions