Automatic continuous integration-Jenkins integrates SpringBoot

  Automatic continuous integration, in short, is that every time the code is submitted, the work of automatic continuous integration is mainly to build, automate testing, and release the project . Jenkins is an automatic continuous integration tool, and gitlab is currently more cutting-edge. The use of automatic continuous integration tools can monitor the running status of the project and reduce the risk of the project. If there are many developers and branches in a project, if their submitted code is not checked, the final merge is often prone to errors. What jenkins mainly does is to check whether the code submitted every time can be run normally. When the code is submitted to the warehouse, it will trigger jenkins to do project construction, testing, release, etc. If it fails, it will notify the administrator, and the administrator can check the availability of the code in the project in real time.


Environmental preparation:

①Project. Before starting to do Jenkins integration SpringBoot, we need to prepare the development environment. SpringBoot case link https://gitee.com/brozer/springboot_practise.git Here, readers can also use their own SpringBoot.
②Code hosting platform. After preparing SpringBoot, we take Code Cloud as an example of hosting platform. Host your own SpringBoot project on Code Cloud.

③ Install jenkins. Before installing jenkins, we need to make sure that we have installed the JDK and configured the Maven environment. Because here we take SpringBoot as an example to explain, all these environments must be configured. We can visit the official website of Jenkins to download the installation package.

One: jenkins configuration

After downloading jenkins, we run jenkins. After running successfully, we will access the local port 8080 by default. During the initial operation, jenkins did not set a password, and needed a string of verification codes to verify. The verification code can be obtained in the running console. After logging in, as shown in the figure. Here, I have created a project.



Before creating the build project task, we have to configure the jenkins environment variable. Click Manage Jenkins—>Configure Glogal Security to remove the checkbox to prevent cross-domain requests.


After saving, we return to the home page, select People on the left, and select the administrator account admin—>Configure. Here, we need the API token of the account to be used for communication authentication between Code Cloud and Jenkins.


Create a build task. Select New Item on the home page, give the task a name (java-app), and use the FreeStyle Project type.

①We configure Source Code Management for the task


②Configure the build trigger


The token here is used for authorization.


③Create a build task script. Click Add build step and select Executive shell. Whenever the project code is submitted to the code cloud, the code cloud will adjust jenkins, jenkins will synchronize the code on the code cloud, and then build the project according to the script steps in the jenkins local environment. By default, jenkins will download the project to root/.jenkins/workspace. We can view the directory where the current build is located with $pwd

echo $WORKSPACE
echo $pwd
mvn clean install -Dmaven.test.skip=true


At this point, our jenkins environment has basically been configured. In addition to configuring the jenkins environment, we also need to ensure that jenkins can be accessed from the external network.


Two: Code Cloud Configuration


We enter the SpringBoot project management configuration page and configure WebHooks.
Write https://admin:[email protected]/job/java-app/build?token=java-token in the URL , the password is empty, submit.

admin: f7c50b51906a07335c5fedfecda4e6aa is the API Token of the previous Jenkins account, used for Jenkins authentication. token=java-token is filled in when the Trigger is built, and is the authorization of the user project.

7c497b3d.ngrok.io is our Jenkins Internet access address.


We can first pass the manual test to see if the code cloud can initiate a build task to jenkins. If the request returns 403, it is possible that Jenkins prevented the use of cross-domain proxy.

Three: running results:



After each code submission, the project can be automatically and continuously built.


Guess you like

Origin blog.csdn.net/Lixuanshengchao/article/details/79053457