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
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
search
text boxThe 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
Screenshot of successful configuration
Finally, click Save at the bottom of the page to save our configuration.
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
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.
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.
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 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