当前位置:网站首页>Gocd is good, but talk about Jenkins
Gocd is good, but talk about Jenkins
2022-06-29 04:14:00 【ThoughtWorks】
Preface
In recent years Docker、 Kubernetes、 Helm、 Yunyuan is in full swing ,Jenkins With the contributions of the open source community and similar CloudBees Blessings of the team . Keep up with technology trends , The output is integrated into Docker、 Kubernetes、 Helm、AWS And so on , also Jenkins X, The original configuration page Manage Nodes also " Quietly " Turned into Manage Nodes and Clouds. On the other hand , Enterprises with good self-study ability , Also based on Jenkins API Develop a set of Devops CICD platform , to Jenkins that " old man " Put on a young coat , The effect is also very ideal .
Jenkins Open source features , There are also a sea of plug-ins , Low learning threshold, etc , Make it a good choice . At least with limited resources , In view of the need to build a few assembly lines in the project ,Jenkins perfect .
Even as a lover of new technology , When you use other new CI Tool time , You might as well look back at this “ old man ”, Some of the general rules contained in it 、 Ideas will let you know how to build an easy-to-use for a project 、 Easy to expand 、 Easy to maintain assembly line .
To improve code reusability Shared Library
If you work for more than one project Code Repo Write more than one jenkinsfile, You will probably encounter a lot of duplicate code in multiple different pipelines , Especially in the projects that serve many micro Services . Most of the time, in order to make things easier, we copy and paste similar logic codes to different jenkinsfile In the middle , But if one day you need to change a little order , Then you'll suffer a little .
and Shared Library Is one of the ways to solve code duplication , Just according to the reasonable division of pipeline sections , Abstract and encapsulate the repeated or common parts of pipeline logic , The code under these shared libraries can be simply referenced in all pipelines , And can greatly shorten jenkinsfile The number of lines of code in , It also makes it easier to read 、 Easy maintenance .
And in the later show Azure Pipelines, Github Actions Seems to know the benefits of reusing function , And the common Tasks/Actions Placed in the public Marketplace in . Developers can use it directly , You can also develop your own software and upload it to Marketplace For more people to use . Users are also exempt from maintaining a separate similar to Jenkins Shared Libray Code warehouse for , Fully staffed . in addition , Cloud native tools Tekton, Among them Task There are similar practices .
Shared libraries are getting bigger , When the calling relationship becomes more and more complex , Have to consider the problem of code quality . Then you need to test the code to ensure quality , How to Shared Library To test ? Of course you can write Jenkinsfile Put it in Jenkins Created in Job To run , You will know if there is a problem with the code when you run . But there is no doubt that this method is not very elegant , Recommended JenkinsPipelineUnit( A shared library unit testing framework ).
Templating JTE
Just like a development framework , The aim is to quickly build a number of standardized projects , The same is true of the functionality provided by the template : For the same type of pipeline , Most build processes are the same , Even the running commands are the same , Such an assembly line The similarity of configuration files is also very high . that Jenkins Templating Engine It is a very good solution for such scenarios .
for example , In the large-scale project of microservices , Often a system is composed of dozens of small microservices , These dozens of microservices need their own CICD The assembly line , To complete the packaging 、 Deployment process , They are the same development framework , The build environment required 、 Tools 、 Testing process 、 The release strategy and so on are all carved out of the same mold .
" people " As its name , Jenkins Templating Engine It is a tool used to make assembly line templating , abbreviation JTE. from JTE The birth time can be seen on the homepage 2019 year 5 month , Quite young . For different types of projects , such as Maven、 Gradle To make some template regulations , In short, it is used to unify the internal pipeline Stage、Steps Logic in 、 Parameters, etc. .
After completing the above code , And installation JTE plug-in unit 、 Configured correctly Jenkins Under the premise of , Add default file in specific business code pipeline_config.groovy after , When you create a new assembly line, you are specific to build configuration Options to choose Jenkins Templating Engine, The assembly line can be built , Just a simple 2、3 That's ok .
whereas JTE The advantages of , These are the following three points :
( originate https://www.jenkins.io/blog/2019/05/09/templating-engine/)
And go to the other CICD Look in the tools , Similar practices can also be seen . for example Gocd Of Pipeline Templates, Azure Pipelines Of templates.
Centralized management Job DSL
If you are going through a microservice project ,Code Repo A large number of , And each Repo All need to pass a Jenkinsfile Define a pipeline . When you face dozens of hundreds Repo, It is a little tedious to manage and maintain them decentrally .Job DSL Plugin Allow to use DSL Create projects programmatically , The operation of job creation is realized through script , Enables you to automate and standardize Jenkins To configure .
This plug-in can not only create various types of Job(Maven jobs、Freestyle jobs、 Assembly line jobs...), Can also create Folder、 Dashboard View、 List View wait . The vivid effect is shown in the figure below ,“ Bury a seed , Harvest a few big trees ”.
At the catalog level of the code base , First of all, it is suggested to follow Project Divide , For each Project Define the individual Seed Job; The second will Job The definition of, etc. is isolated from the logical implementation , This ensures that xxx.jenkinsfile The independence of the content in , And is adopting Job DSL After the plug-in , For the original jenkinsfile There is no need to make significant changes , Take it and you can use it .
This tool will undoubtedly Pipeline As Code The idea of has evolved a step further , The pipeline creation process is also coded . And then in Jenkins In practice , If you want to pursue more configuration coding , Let's see. Jenkins Configuration as Code, abbreviation JCasC. This tool can completely convert most Jenkins Resources for 、 Configuration coding , Installing a plug-in 、 To configure Github Server、 Management Certificates 、 New tasks can be completed through files , Don't need to UI Do any operation on the interface .
Postscript
The above ideas provide a corresponding implementation in this paper , But it goes far beyond the methods mentioned , Of course, there are more or less similar methods , But we can't change without our ancestors . Even if there are more CICD The emergence of new tools , Maybe we can find another way in some small places , But the general solution can not bypass the existing ideas to solve the problem . For example, in Azure Pipelines in , Templates Can provide similar functions Shared Library and JTE The function of , Only the implementation form is different , The core idea is the same .
Specific use also needs to be combined with project attributes 、 Branching strategy 、 Release strategy 、 Rights management 、 Server environment and other aspects shall be considered comprehensively , There are also many similar to Nightly Build This construction strategy is worthy of our reference .“ All roads lead to Rome ”, How to save time 、 Save effort to achieve our ultimate goal , And how to maintain the assembly line after the completion , It is worth thinking and designing .
The copyright of this article belongs to Thoughtworks Owned by the company , If you need to reprint, please leave a message in the background .
边栏推荐
- 技术:如何设计zkVM电路
- SEAttention 通道注意力机制
- Analysis on the types of source code anti leakage technology
- 从零到一,教你搭建「以文搜图」搜索服务(一)
- 你为什么做测试/开发程序员?还能回想出来吗......
- C language -- branch structure
- 女程序员晒出5月的工资条:工资是高,但是真累,网友评论炸锅了
- The virtual machine MySQL cannot be connected to the local computer
- c语言 --- 分支结构
- 1019 digital black hole
猜你喜欢

Technology: how to design zkvm circuit

云原生周报 | Grafana 9正式发布;云原生词汇表中文版现已上线

Anaconda's own Spyder editor starts with an error
![[FPGA mathematical formula] use FPGA to realize common mathematical formulas](/img/b9/e6f219738b106a96b0f5323ee61cca.png)
[FPGA mathematical formula] use FPGA to realize common mathematical formulas

自己动手搭建一个简单的网站

Implementation of b+ tree index based on xlsx

The five levels of making money, which level are you on?

How to keep database and cache consistent

yolox出现 RuntimeError: DataLoader worker (pid(s) 17724, 1364, 18928) exited unexpectedly

Anaconda自带的Spyder编辑器启动报错问题
随机推荐
Influence of air resistance on the trajectory of table tennis
开发者方案 · 环境监测设备(小熊派物联网开发板)接入涂鸦IoT开发平台
Implementation of thread pool based on variable parameter template
请问大佬,Oracle CDC报错 Call snapshotState on closed sou
自己动手搭建一个简单的网站
Nuxt - set SEO related tags, page titles, icons, etc. separately for each page (page configuration head)
欧拉开源社区第二届理事会第二次会议召开,新华三、超聚变和龙芯中科成为理事会成员单位
On June 27, 2022, I have the right to choose the journey of the summer vacation.
I came from a major, so I didn't want to outsource
【布里渊现象】光纤布里渊温度和应变分布同时测量系统研究
Daily practice - February 15, 2022
你为什么做测试/开发程序员?还能回想出来吗......
My creation anniversary
Developer scheme · environmental monitoring equipment (Xiaoxiong school IOT development board) connected to graffiti IOT development platform
[laravel series 8] out of the world of laravel
webassembly学习-动态链接
HCIE-Security Day41:理论学习:信息收集与网络探测
What is the dry goods microservice architecture? What are the advantages and disadvantages?
String不同创建方式的区别
Remediation for Unsafe Cryptographic Encryption