当前位置:网站首页>Unit test ci/cd
Unit test ci/cd
2022-06-28 13:18:00 【Swuagg】
Catalog
1.3 CI/CD technological process
2.3.1 Github Actions The advantages of
2.3.2 Github Action The shortcomings of
2.3.3 Jenkins The advantages of
2.3.4 Jenkins The shortcomings of
3 Unit Test CI( Unit test continuous integration )
3.2 Jenkins install / To configure GitHub Pull Request Builder plug-in unit
3.4 Github newly build webhook
Preface
At present, the effect is : stay Github carry Pull requests when , Automatic triggering Jenkins Perform unit tests , And feed back the execution results to Github Pull requests page .
Unit Test CI The configuration process :
1 CI/CD
1.1 What is? CI
Continuous integration (CI): Is continuous automatic detection after source code changes 、 Pull 、 The process of building and unit testing .
The goal of continuous integration : Is to quickly ensure that developers' newly submitted code changes are correct 、 Can be integrated , And suitable for further use in the code base .
notes : The behavior that accompanies continuous integration is continuous testing .
1.2 What is? CD
Continuous delivery (CD): Automatically publish validated code to the repository .
The goal of continuous delivery : It is to have a code base that can be deployed to the production environment at any time .
Continuous deployment (CD): Automatically publish applications to the production environment .
notes : Continuous delivery and continuous deployment , Is continuous through automation Pipeline The way , The act of publishing artifacts into the environment . These two are sometimes used interchangeably , There is no need to dwell on these semantics .
1.3 CI/CD technological process
CI/CD technological process : Also known as CI/CD Assembly line , Continuous delivery line .
Continuous delivery covers from demand 、 Design 、 Development 、 structure 、 test 、 The process of the whole online process 、 Tools 、 Method 、 Platformized input to output .
2 CI Platform selection
from 2018 year 10 month Github Actions When it appears , Many articles discuss CI Platform selection , yes Github Actions, still Jenkins.
2.1 Github Actions
Github Actions It's an event driven (Push,Pull requests etc. ) Continuous integration and continuous delivery tools , Allows you to automate the construction of 、 The process of testing and deploying applications to various environments .
let me put it another way ,GitHub hold CI/CD Many operations , Like grabbing code 、 Operation test, etc , be called Actions. Developers can write their own action, You can also use the... Provided by other developers action, So the whole CI/CD The process , It becomes multiple actions The combination of , This is it. Github Actions.
2.2 Jenkins
Jenkins It's a use. Java Write the open source automation server , For automated continuous build 、 Workflow for testing and deploying software projects .
Jenkins It is mainly realized through rich plug-ins CI/CD, The following figure represents a simple Jenkins workflow , It is from Github Extract code from , Build a from the code docker Mirror image , It is then tested and pushed further to the remote repository DockerHub.
2.3 Github Actions Vs Jenkins
Jenkins and GitHub Actions Can be created automatically 、 test 、 Release 、 Workflow for distributing and deploying code . Generally speaking, for most companies , You don't need to develop one yourself CI platform , And there is no absolute difference advantage between tools , Here is just an objective description of the relationship and similarities and differences between the two .
2.3.1 Github Actions The advantages of
Easy to use : Github Actions Very friendly to beginners . You only need one YAML The file is ready to use . For startups / A small company , Your developers may already be interested in YAML Know something about , therefore Github Actions As CI/CD The platform is a logical choice .
Setup and maintenance : Use Jenkins, You will run it on a custom server . This means that you must continue to maintain Jenkins The server . however ,Github Actions Provides you with the CI/CD Free runner for operation . These operators are controlled by Github Own and maintain , But you can also add a self managed runner .
2.3.2 Github Action The shortcomings of
lock : Use Github Actions, You are more or less related to Github As a source code management system . Use Jenkins Allows you to store code in Github、Gitlab、BitBucket And so on .
maturity : Jenkins Already exists and is better than Github Actions The more mature .Github The operation is relatively new , Therefore, there is less community support .
2.3.3 Jenkins The advantages of
Use Jenkins One of the advantages of is that it is open source and free , Unlike its counterpart Github Actions yes “ Free value added ”.
Plug ins can be used to support caching , The files from the previous build are cached and re implemented in the new build as needed .
2.3.4 Jenkins The shortcomings of
Jenkins There are many plug-ins available to users , Unfortunately , Some of these plug-ins are not maintained regularly by developers . Therefore, it is necessary to check whether the plug-in supports correctly before use .
It is highly dependent on plug-ins , Sometimes it is difficult to find the basic functions of plug-ins .
You must maintain and manage by yourself Jenkins Infrastructure .
Due to the uncertainty of the load on the server , At remote ( cloud ) On the server Jenkins The cost of may not be predictable . These workloads include the amount of code 、 Quantity of artifact 、 Submission times, etc .
2.3.5 Similarity
Jenkins Use Declarative Pepeline Create workflow , These workflows are similar to GitHub Actions Workflow documents .
Jenkins Run a set of steps using phases , and GitHub Actions Then use jobs to group one or more steps or a single command .
Jenkins and GitHub Actions Support for container based builds .
Steps or tasks can be reused and shared with the community .
2.3.6 The main difference
Jenkins There are two types of syntax for creating pipes :Declarative Pipeline and Scripted Pipeline. GitHub Actions Use YAML Create workflows and profiles .
Jenkins Deployment is usually self managed , Users maintain servers in their own data centers . GitHub Actions Provide hybrid cloud methods by hosting a runner that you can use to run jobs , It also supports self managed runners .
Github Actions vs Jenkins: A further comparison is shown in the following table :
GitOps Is to use the source version control platform Git The practice of managing infrastructure and configuration .
Asynchronous integration simply means that builds are performed at the same time , This makes the workflow faster . as for Jenkins, Synchronous construction is the main content .
Ad Hoc Workflow: For in Github Actions Build that occurs in , It will monitor git Event trigger . On the other hand ,Jenkins Many jobs can be performed , for example : function bash Script 、maven buildsm powershell etc. . If you need to run jobs to run regularly in sequence without linking to the code base , that Jenkins Can do this .
2.4 Summary
be based on Jenkins The maturity of , And project compilation Unity Complexity , We finally chose Jenkins As CI/CD Tools for .
3 Unit Test CI( Unit test continuous integration )
At present, the effect is : stay Github carry Pull requests when , Automatic triggering Jenkins Perform unit tests , And feed back the execution results to Github Pull requests page .
The following describes in detail the use of GitHub pull request when Jenkins An automated build Configuration process , about Jenkins Setting up and configuring the environment , I won't go into details here .
3.1 Github Generate token
GitHub Click on your avatar , Choose in turn Settings > Developer settings > Personal access tokens, Click on Generate new token Button to enter new Token Generate page , Check the options shown in the figure , spot Generate token Button generation Token And will generate Token Copy and save .
3.2 Jenkins install / To configure GitHub Pull Request Builder plug-in unit
1、Jenkins > System management > Plug-in management > Optional plug-ins , Search for GitHub Pull Request Builder, Then select direct installation
2、 stay Jenkins Add Credentials,Kind Place selection Secret text, Secret Fill in GitHub Of Token, Later configuration GitHub Pull Request Builder Need to use it .
3、 And then use GitHub User name and password to create another Credentials, It will be used when configuring tasks later . Of course, if you have already added , No more configuration .
4、 And then in jenkins > System management > System settings > GitHub Pull Request Builder The following configuration
GitHub Server API URL: The default is https://api.github.com , Fill in the enterprise version https:// domain name /api/v3/.
Credentials: Use... Before choosing GitHub Generated token Created Credentials.
Fill in the contents above , You can use the... Below Connect to API Button to verify the connection GitHub If there is something wrong ,Check repo permissions Button to verify permissions .
3.3 Jenkins Configure tasks
3.3.1 A new task
1、 Create a free style task , Then configure the task
2、 Will project's GitHub URL Add to GitHub Project office ( Items that can be imported into the browser )
3.3.2 Source code management
Add code in the configuration source code management GitHub Address in ,Credentials Select above to use GItHub Created with your account and password Credentials.
Refspec:
If you just want to build PR, Please put refspec Set to +refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*
If you want to build PR And branches , Please put refspec Set to +refs/heads/*:refs/remotes/origin/* +refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*
Specify Branch : Fill in ${sha1}, If you want to use the submitted pr, Fill in this field ${ghprbActualCommit}
3.3.3 Build trigger
Add the administrator list to the build trigger , Check Use github hooks for build triggering And click the advanced button on the back ,White list Add... To allow for this task pull request Of GitHub The user account .
3.3.4 Build steps
1、 Build here, select the appropriate build tool according to your project situation , My project uses Gradle Build, so choose Invoke Gradle script.
2、 If you add Set build status to “pending” on GitHub commit This is the building step , So when building GItHub Project Pull requests Will show pending state .
3.4 Github newly build webhook
1、 stay GitHub Corresponding project remote warehouse ,Settings > Webhooks in , Create a new one webhook, Fill in the following figure Jenkins Address .
2、 Choose Let me select individual events, Check Pull requests Options .
3、 If GitHub Be able to connect correctly Jenkins, that Recent Deliveries There will be an error free record below .
4、 Here we are , Configuration is complete . Next, send a to a branch of the project pull request test . Hair PR after GitHub Displayed on the pending check state
5、Jenkins Successfully triggered a build on
6、 When successfully built ,GitHub The above status is changed to successful checks.
3.5 Follow up improvement
Github Visualization of single test results
Github When the single test result fails or is abnormal , Don't allow PR
Github Support jump Jenkins Specific construction tasks
...
3.6 improvement
Github Support jump Jenkins Specific construction tasks :
4 Acknowledgement
【faun.pub】
边栏推荐
- 电驴怎么显示服务器列表,(转)如何更新电驴服务器列表(eMule Server List)
- Hubble数据库x某股份制商业银行:冠字号码管理系统升级,让每一张人民币都有 “身份证”
- MySQL多表联合查询
- 如何在熊市中寻找机会?
- flex布局中的align-content属性
- G1垃圾收集器中重要的配置参数及其默认值
- Fs7022 scheme series fs4059a dual two lithium battery series charging IC and protection IC
- Vscode shortcut key
- Deep understanding of Bayes theorem
- Class structure in C language - dot
猜你喜欢
MySQL multi table joint query
go template with...end遍历用法
Arduino-ESP32闪存文件插件程序搭建和上传
Shareit a une force exceptionnelle et se connecte au top 7 de la liste mondiale des forces IAP
2022年中国运维安全产品市场规模及发展趋势预测分析
开源项目维权成功案例: Spug 开源运维平台成功维权
5A synchronous rectifier chip 20V to 12v2a/5v4.5a high current 24W high power synchronous rectifier chip high current step-down IC fs2462
Après avoir échoué à l'examen d'entrée à l'Université de technologie de Harbin, vous devez rester à l'Université en tant que « chercheur » après avoir obtenu votre diplôme.
Stm32f1 and stm32cubeide programming example - matrix keyboard driver
Google Earth Engine(GEE)——联合国粮农组织全球有机土壤面积(1992-2018年度)
随机推荐
How to solve the data inconsistency between redis and MySQL?
简历模板百度网盘自取
Elastic box auto wrap demo
Mobile web training day-1
G1垃圾收集器中重要的配置参数及其默认值
Centos6.5 php+mysql MySQL library not found
Class structure in C language - dot
5A同步整流芯片 20V转12V2A/5V4.5A大电流 24W大功率同步整流芯片 大电流降压IC FS2462
高考失利進哈工大,畢業卻留校要當“探索者”,丁效:科研就是厚積薄發
Arduino-ESP32闪存文件插件程序搭建和上传
词云的可视化设计教程
中国数据库技术大会(DTCC)特邀科蓝SUNDB数据库专家精彩分享
数启扬帆,智聚人才 | 腾讯云数据库 & CSDN 工程师能力轻量认证发布会重磅来袭!...
Scratch travel photo album Electronic Society graphical programming scratch grade examination level 1 true questions and answers analysis June 2022
求职简历的书写技巧
codeblocks mingw安装配置问题
Hang Seng Electronics: lightdb, a financial distributed database, has passed a number of evaluations by China Academy of communications technology
FS7022方案系列FS4059A双节两节锂电池串联充电IC和保护IC
SHAREit實力出眾,登陸全球 IAP 實力榜 Top7
微服务稳定性保障