Preface:

Recently, I have made automatic deployment of several projects in my hand and recorded the process simply in graphic form.

1. Jenkins installation

Install Jenkins for Linux:

Refer to the previous article

Go straight to the automated workflow

process

Gitlab submits code -> Jenkins triggers to execute the corresponding shell

steps

  1. Gitlab build a project warehouse… (Already skipped)

  2. Open Jenkins, log in, and create a project as Required by Jenkins

    1). Click on the left to create a new item

2). Enter the task name (create as required) and click OK

3). Select Discard old Builds under General and fill in 5 for the number of days and 3 for the maximum number (see personal needs).

4). Go to the configuration interface => source Control office select Git-> insert Git clone address (directly copy on gitlab)

5).credentials Click Add (select the added ones directly on the left). Add your gitlab account password and select your Git account password on the left after completion

5). New click on Clean before Checkout

7). Find the Build trigger and tick Build when a change is Pushed to gitlab. GitLab webhook URL

Steps 7 and 8 are required to configure Webhook in GitLab below

8). After checking the box, click Advanced and click Generate below to Generate Secret Token.

9). Copy the variable URL of step 7, and the token of step 8, then perform step 3 below, Gitlab triggers Jenkins,

10). In the following build, click Add Build Step, add Execute Shell first, and fill in the command at the command

// The command can be used freely, the code can be packaged after submission, then deployed, etc... This is just a code packaging deployment example
export PATH=$PATH:/usr/local/yarn/bin
nvm use 12.161.
yarn cache clean
yarn install
Copy the code

11). Click Save and skip to step 4 below

  1. Gitlab trigger Jenkins,

    1). Find your GitLab project, click Settings =>webhooks

    2). Fill in the variable URL of step 7 above in the right URL, and fill in the Secret Token generated in step 8 to generate Secret Token

    3). Check Push Events. This means your code Push will trigger Jenkins

    4). Clicking Add Webhook will generate a list item below

    5). Click the list item below to configure the list item and click Test=>Push event. Hook executed successfully: HTTP 200

To successfully add webhook, click Test. If successful, you can see the build task execute in Jenkins

  1. test

Go back to the Jenkins home page, enter the project you just created, click build-Now, the build progress will appear below, the first build may be slow

If it turns red, it means the build failed, so you can click on the relevant task and see the console output to see what went wrong,

  1. Code submission test

Submit the new code to GitLab. After the submission is successful, we will see whether Jenkins has automatically built it. If so, it means that the whole automated code quality test has been completed

summary

Continuous integration is a software development practice in which team development members integrate their work frequently, usually at least once per member, which means that multiple integrations may occur per day. Each integration is verified by an automated build (including compilation, release, and automated testing) to find integration errors as quickly as possible. Many teams find that this process greatly reduces integration problems, allowing teams to develop cohesive software more quickly.

Actually, I was going to say do it yourself! Try it yourself! Try it yourself! Just try it a few more times