当前位置:网站首页>Jenkins basic knowledge ----- detailed explanation of 03pipeline code
Jenkins basic knowledge ----- detailed explanation of 03pipeline code
2022-07-06 02:51:00 【weixin_ thirty-nine million four hundred and thirty thousand fi】
jenkins-pipeline Two codes in :Declarative and Scripted
What is commonly used is Declarative, Clear and simple structure ,Scripted More flexible
Declarative Pipeline Valid basic statements and expressions in follow and Groovy Rules with the same syntax , But there are the following exceptions :
1)Pipeline The top layer of the must be a block , Specifically :pipeline { }
2) No semicolon as statement separator . Each declaration must be on its own line
3) Blocks can only contain chapters , Instructions , Step or assignment statement .
4) Attribute reference statements are treated as parameterless method calls . So for example ,input Be regarded as input()
Here are Declarative Pipeline Code :
explain :
There's a Declarative Type of Pipeline, This , I said before , Basically, this is used in actual development . although Scripted Mode Pipeline The number of lines of code is reduced , Very short , above Declarative Yes 20 Line code , If you use Scripted Pattern , Just 10 Line code . however Scripted The script is very flexible , It's not easy to write , It's not easy to read , It is equally difficult to maintain . Let's study first Declartive The meaning of the code inside , Some basic knowledge is Scripted Also have , Some don't .
1) The first line is lowercase pipeline, Then a pair of Daguo {}, Anyone who has studied code knows , Inside the braces is the code block , Used to isolate from other code blocks .pipeline Is a syntax identifier , In front, I call keywords . If it is Declarative type , It must be pipeline {} Start like this . Of course, script files ,pipeline It is not required to be the first line of code . in other words pipeline There can be other codes in front , For example, import statements , And other function codes .pipeline It's an execution pipeline Code entry ,jenkins You can start with this entry to implement different stage
2) The second line agent any,agent Is a syntax keyword ,any It's a option type .agent It means agency , This and choice are used jenkins The machine on the platform performs task construction . Of course jenkins only one master node , No second node machine was added , Later article , When we specialize in learning agent When it comes to this command , Let's introduce how to add a node . Wait until a new node is added , We can choose to use this place master It is also a slave machine to perform tasks , therefore any It refers to any available machine , Of course, my environment is master.
3) The third line stages{}, stages There are many stage It means , That is to say a stages It can contain more than one stage, You can also see from the above code results . It says three stage, According to your task needs , You can write more than ten .
4) In the fourth row stage('Build') {}, This is a specific definition stage, Generally one stage It refers to the completion of a business scenario .‘Build’ Is to think of a name for this task . This name can appear in Jenkins On the task page , The picture at the end of my previous article can show three stage The name of , Namely Build,Test, and Deploy.
5) The fifth row steps{}, Literally, it means many steps . Just to mention here , I saw it steps, Of course, step This instruction . Generally speaking , One steps{} There are just a few lines of code , Or a try catch sentence .
6) Sixth elements , This place can define variables , Write calling module code, etc . here , I will use it. Groovy grammar , Wrote a print statement . If your machine is not installed groovy, You install python, You can write python The print statement of , Or use linux Of shell, for example sh "echo $JAVA_HOME"
hinder stage The meaning is the same , It says three state, Three business scenarios are described , For example, packaging build, And testing Test, And deployment , These three in series are a typical CD Pipeline technological process . Actually, it is definitely not written like this , because Test There are many stages , And different test types . These different test types , Can be subdivided into many stage To complete .
scripted Code :
This code , There are two differences from the above . The first is Scripted The pattern is node{} start , did not pipeline{}, This difference is easy to know . The second thing to point out is ,scripted Not in mode stages This keyword or instruction , Only stage. It can actually node('Node name') {} Let's start with ,Node name Is from the node or master Name of node .
Refer to the post :https://blog.csdn.net/u011541946/article/details/83152494
边栏推荐
- codeforces每日5题(均1700)-第六天
- 华为、H3C、思科命令对比,思维导图形式从基础、交换、路由三大方向介绍【转自微信公众号网络技术联盟站】
- MySQL winter vacation self-study 2022 11 (9)
- 主数据管理理论与实践
- tcpdump: no suitable device found
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
- Single instance mode of encapsulating PDO with PHP in spare time
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
- Codeworks 5 questions per day (1700 average) - day 6
- The difference between sizeof and strlen in C language
猜你喜欢
【若依(ruoyi)】启用迷你导航栏
主数据管理理论与实践
What is the investment value of iFLYTEK, which does not make money?
[matlab] access of variables and files
1. Dynamic parameters of function: *args, **kwargs
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
[ruoyi] set theme style
米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
随机推荐
MySQL winter vacation self-study 2022 11 (8)
CobaltStrike-4.4-K8修改版安装使用教程
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
JS events (add, delete) and delegates
主数据管理(MDM)的成熟度
Large scale DDoS attacks take Myanmar offline
How to improve the enthusiasm of consumers when the member points marketing system is operated?
Shell script updates stored procedure to database
如何精准识别主数据?
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.3 linear algebra_ Learning thinking and exercise answers
[ruoyi] set theme style
#PAT#day10
PMP practice once a day | don't get lost in the exam -7.5
DDoS "fire drill" service urges companies to be prepared
主数据管理理论与实践
Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
A copy can also produce flowers
【若依(ruoyi)】ztree 自定义图标(iconSkin 属性)
Referenceerror: primordials is not defined error resolution
Redis cluster deployment based on redis5