Realize manual pull code cloud code based on jenkins, realize semi-automatic deployment

This article immediately follows the above Play jenkins-install jenkins on your own server, if you are unfamiliar, you can review it first.

Let’s use jenkins to manually pull my project in Code Cloud this time. Before, we log in to the server, then switch to the specific directory, and then deploy after the pull is completed. This kind of human operation is too tiring, so we must use tools to complete , Let me have more time to play the show.

The specific goal to be achieved in this article: Use jenkins to complete manual deployment (semi-automatic deployment)

ps: My server: CentOs8 Linux

Planned several goals to achieve

Install gitee (code cloud) plugin

Jenkins does not support gitee by default, but you only need to install a plug-in to get it done. This plugin gitee has been provided.

The specific installation steps are as follows

Plugin configuration

The plug-in was installed in the previous step, and now we need to configure the plug-in.

Open the specific configuration item: Jenkins -> Manage Jenkins -> Configure System -> Gitee Configuration -> Gitee connections

  1. Domain select Global credentials
  2. Type (Kind) select Gitee API Token (Gitee API Token)
  3. Scope (Scope) Choose the scope you need, according to which scope you want this credential to be used in, I chose the global
  4. Gitee API Token Enter your code cloud private token to obtain the address: https://gitee.com/profile/personal_access_tokens
  5. ID and description (ID, Descripiton), enter the ID and description you want. (Write it casually, just for display)

Screenshot of successful configuration

Finally, click Save at the bottom of the page to save our configuration.

New build task

Here comes the configuration of the specific project. After the configuration is completed, there is no need to frequently log in to the server for manual deployment.

Go to Jenkins -> New Item, name and enter'Test Code Cloud' (the project name is self-made), select Freestyle project (free style) and save to create a build project.

Click the source code management tab

  1. Click Git, Repository URL to enter the git address, and select None for Credentials (provided that we have configured the public key of the server where jenkins is located on the code cloud, the server can directly use the git command clone or pull the code of the code cloud)
  2. Click Advanced, enter origin in Name, and enter +refs/heads/:refs/remotes/origin/ +refs/pull//MERGE:refs/pull//MERGE in Refspec
  3. Branch Specifier (blank for'any') enter origin/${giteeSourceBranch}, here I follow the default configuration and use the master branch

Since I haven't configured gitee ssh yet, I use http protocol here, and then configure gitee account password authentication.

At this point, the basic configuration of the gitee plug-in is completed, and the rest is the operations that need to be done when the gitee code is updated to the server, such as executing npm i, npm run build and then deploying the service. Of course, all the configuration is not finished yet, there is another very important operation, that is, automatic deployment, that is, trigger configuration.

Test configuration is successful

Pull to the end of the page, find the build option, add a build step, select execute shell, and enter echo hello to test the result of our build.

Screenshot of successful build

As you can see from the log, Jenkins first pulled the git project code, and then executed the shell script we configured.

Project deployment

We are just one step away from getting our project up and running. Everyone here is the most familiar with it, just look at the command.

npm install //Installation dependencies
npm run build  //Build packaging
PORT=9001 pm2 start app.js -n testMyproject --watch -- env:production //Use pm2 to start the service, and set the port and file monitoring, the code changes will automatically restart

At last

At this point, our entire configuration is complete, and the project can be deployed in a semi-automated manner in the future. Although it is semi-automated, it is much more convenient than manual deployment before. Of course, our ultimate goal is to automatically deploy, and we will continue to follow the article.

Reference material: https://gitee.com/help/articles/4193#article-header0

Click here for support

Recommended Posts

Realize manual pull code cloud code based on jenkins, realize semi-automatic deployment
Use jenkins to automatically pull code cloud code to achieve automated deployment