当前位置:网站首页>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
边栏推荐
- 主数据管理理论与实践
- Maturity of master data management (MDM)
- PMP practice once a day | don't get lost in the exam -7.5
- How does yyds dry inventory deal with repeated messages in the consumption process?
- 力扣今日題-729. 我的日程安排錶 I
- 2.11 simulation summary
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
- 故障分析 | MySQL 耗尽主机内存一例分析
- 微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
猜你喜欢

Taobao focus map layout practice

Installation and use tutorial of cobaltstrike-4.4-k8 modified version
![[ruoyi] enable Mini navigation bar](/img/28/a8b38aecd90c8ddc98333f0e2d3eab.png)
[ruoyi] enable Mini navigation bar

2345文件粉碎,文件强力删除工具无捆绑纯净提取版

4. File modification

#PAT#day10

Shell script updates stored procedure to database

My C language learning record (blue bridge) -- on the pointer

【若依(ruoyi)】启用迷你导航栏

2022.02.13
随机推荐
球面透镜与柱面透镜
会员积分营销系统操作的时候怎样提升消费者的积极性?
A copy can also produce flowers
CSP date calculation
Briefly describe the implementation principle of redis cluster
07 单件(Singleton)模式
JS regular filtering and adding image prefixes in rich text
codeforces每日5題(均1700)-第六天
Thinking on Architecture Design (under continuous updating)
Apt installation ZABBIX
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
GifCam v7.0 极简GIF动画录制工具中文单文件版
MySQL winter vacation self-study 2022 11 (8)
My C language learning record (blue bridge) -- on the pointer
Maturity of master data management (MDM)
Qt发布exe软件及修改exe应用程序图标
Differences and usage scenarios between TCP and UDP
CobaltStrike-4.4-K8修改版安装使用教程
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23