Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Jenkins Automation build tools for Agile Development

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to use Jenkins automated build tools for agile development", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use Jenkins automated build tools for agile development" article.

I. Preface

Jenkins is an automated build tool that can build back-end Java projects based on Maven and front-end vue projects based on nodejs, with a visual web interface.

Automatic build means that packaging scripts are executed according to certain policies. Compared with ordinary script builds, Jenkins has the following advantages:

Multiple projects can be built simultaneously in the build queue, including front-end and back-end projects

Timing construction

The code repository triggers the build (normal scripts cannot be implemented)

Jenkins embodies a kind of project management thinking: a thoughtful assistant to developers who focuses on business development; early code integration (including front and rear) to identify problems as early as possible; and isolation of the construction environment from the development environment to make adequate preparations for migration to the production environment.

The whole construction process is automated without human participation, and it is easy to achieve efficient project deployment and migration with Docker.

II. Installation and use

Jenkins is a tool, and since it is a tool, there is an alternative, so there is no need to spend working time figuring out how the tool works. It makes more sense to focus on how to use Jenkins to improve agile development efficiency.

In practice, the scripted construction of the project is written into a command script with shell and attached to the project. Even if Jenkins is not used, the automatic construction of the project can be achieved by executing the shell script. The main considerations for doing so are as follows:

Enhance expansibility

Even without Jenkins, the project can complete the build, increasing the expansibility of the build.

Reduce dependence on Jenkins

Let Jenkins assume the role of practical scheduling, and the specific construction process is completed by standardized scripts.

Now that the shell script can automate the build, do you still need to use Jenkins, or does it conflict? The answer is no conflict. Using shell scripts with Jenkins has two major advantages:

Using the shell script, you must log in to the target server and have the corresponding permissions before you can execute the shell script. Jenkins can use a pair of accounts and passwords to manage the visual Web interface to trigger build events without logging in to the target server.

Build on demand, after the developer has submitted the code, send a signal to the Jenkins server to trigger the build.

(1) installation

Use the portal to install quickly, use the recommended plug-in after startup, and install the domestic plug-in source, so the installation speed is fast.

1. Check the initial password cat ~ / .jenkins/secrets/initialAdminPassword2 and modify the default workspace

The default workspace path is ~ / .jnkins. After the project is built in the user space running the Jenkins program, the path may not be found if you want to run it in a third-party container. Modifying the default workspace or giving executable permission to the resource directory can solve this problem.

After the installation is complete, start the program temporarily and confirm whether the Jenkins_HOME variable needs to be modified. Subsequent initialization and plug-in installation are related to this path. There are many ways to modify this variable, the larger granularity is configured in the PATH environment variable, and the smaller granularity is configured in the container running the Jenkins project.

Modify the configuration file context.xml of Tomcat to add a line of configuration

Note: the default value of JENKINS_HOME is the user space corresponding to the user of the startup process, which becomes the new path after modification before startup.

(2) use

If the remote APiToken trigger does not work in the configuration, please read the secret-free login chapter.

1. Build configuration

Building the Jenkins project configuration in a scripted way is very simple, although there are a lot of fancy configurations built in, and you don't need it here, you don't need to care.

You just need to add the execute shell script command to the build. The environment configuration listed in the appendix is completed on the host, not within the Jenkins service. You can use the default value.

2. Add items

Clone the source code of the project to be built locally on the host and execute the shell script to complete the manual build. Create a new empty project with the same name in the Jenkins management workbench, copy the cloned source code to the workspace of Jenkins, the default location is / root/.jenkins/workspace, and entrust Jenkins to manage the project automatically.

(3) secret-free login

To trigger a build event using URL, you need to configure secret-free login, that is, to trigger a build event by calling a shell script remotely without entering a user name and password. This shell script is essentially a GET way to request a specified path. The operation process is as follows:

(1) install plug-ins

Install the Build Authorization Token Root Plugin plug-in and ignore this step if it already exists. The function of this plug-in is to generate Token for the currently logged-in user to facilitate subsequent authentication. A user can configure multiple token.

(2) Project configuration

Add a token configuration to the specified project, which can reuse a token or set a separate token for each project, depending on your needs. The use of token triggers will not take effect until this configuration is added.

(3) the client uses

Write scripts, distribute them to developers, and automated builds can start happily. When using curl multiple arguments, the & symbol needs to be escaped.

Curl {Jenkins URL} / buildByToken/build?job= {Project name}\ & token= {token}

At this point, CI/CD agile development configuration is complete.

Third, trigger strategy

Build events can be defined according to different policies, and timing is passively triggered; URL and hook programs are actively triggered.

(1) timing trigger

There are many ways to realize the timing trigger. Using the CentOS server built-in timing scheduler is a lighter solution. The implementation principle is to run the shell script at the specified time node, in which the shell script is the carrier of the project construction. If you simply want to build the project on a regular basis, it is recommended that you use this solution. Jenkins is a bit cumbersome.

(2) URL trigger

Use a script to simulate or access the URL in a browser to trigger a build event. This approach is the representative of building on demand, which is often used in development. After submitting the code, the software developer actively triggers the build event, which is more efficient in this way.

Build Triggers

A build trigger means that the Jenkins starts building a specified task as soon as it receives a signal.

Check [Trigger builds remotely] and set [Authentication Token]

# [Service prefix] / job/ [Task name] / build?token= [token] JENKINS_URL/job/job-vue/build?token=TOKEN_NAME

The build signal can be triggered by using the curl script.

(3) Hook trigger

The hook program is configured in the code repository and the code warehouse server is allowed to access the Jenkins server. The hook program triggers a build event when the developer submits the code.

The hook trigger looks beautiful, and there are certain prerequisites in the actual operation: first, the construction time of the project should not be too long; second, the code should not be submitted too frequently.

Appendix, tool use 1, language setting

Add the [locale] plug-in in "system Management"-> "plug-in Management". In * * system Management * *-> * * Global configuration * *, add [en_US] under the locale column, and check the option that takes effect for all users.

It is recommended to use the English interface (can be changed to Chinese), and it is awkward to operate in a mixture of Chinese and English.

2. Build environment list serial number function and requirements reference materials 1JavaJava program basic running environment, using jdk can not use jre (need to compile Java source code) 2maven to build Java project, in order to improve construction speed, you need to configure domestic warehouse source [Maven user manual] 3NodeJS build front-end project 4git pull remote warehouse code 5ssh secret-free login authorization to pull remote warehouse code Authorization to log in to the remote server (deployment after construction) [SSH user manual] 3. Environment configuration

1 、 Maven Configuration

Configuration item configuration content Default settings provider/usr/local/maven/conf/settings.xmlDefault global settings provider/usr/local/maven/conf/settings.xml

2 、 JDK

Configuration item configuration content JAVA_HOME/usr/local/java

3 、 Git

Configuration item configuration content Path to Git executable/usr/local/git/bin/git

4 、 Maven

Configuration item configuration content MAVEN_HOME/usr/local/maven

5 、 NodeJS

Configuration item configuration content Installation directory/usr/local/nodejs/bin4, task configuration

1 、 Source Code Management

Source code control is the premise of Jenkins work, that is, to be able to obtain the task source code, it is the premise of automatic construction of subsequent code.

The source code is hosted on GitHub and is a private repository, and proper access to the git repository by Jenkins requires authorization.

# authorize https://gitee.com/decsa/ucode-cms-vue.git# based on http username and password, authorize git@gitee.com:decsa/ucode-cms-vue.git based on public key and private key

In order to improve work efficiency and promote teamwork, ssh certification is selected here.

Ssh-keygen-t rsa-C "982361244@qq.com"

Copy the string in the file [~ / .ssh / id_rsa.pub] to the GitHub setting, and after configuration, you can avoid pulling the GitHub private repository code.

For more information, please see [SSH user Manual]

2 、 Build Triggers

A build trigger means that the Jenkins starts building a specified task as soon as it receives a signal.

Check [Trigger builds remotely] and set [Authentication Token]

# [Service prefix] / job/ [Task name] / build?token= [token] JENKINS_URL/job/ruoyi-vue/build?token=TOKEN_NAME

The task can be built immediately through the browser of any logged-in server or using the curl script.

3 、 Build

Back-end projects are usually built using Maven, select [Invoke top-level Maven targets] in the drop-down box, and then configure the following command in the Goals column

Clean install

After this step, you can find the built project release package in the workspace.

4 、 Post-build Actions

Start this operation after the task has been built. Docker is usually used to build a project release package into an image, and then publish it to the image repository. After the executable image is published to the image repository, there are two more common subsequent scenarios that interact with the application server.

Jenkins is authenticated by authorization, logs in to the target application server, pulls down the corresponding image, and then starts it using a script.

Manage task image publishing automatically by using K8s container service.

The above is about the content of this article on "how to use Jenkins automated build tools for agile development". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report