当前位置:网站首页>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
边栏推荐
- Force buckle 146 LRU cache
- Thinking on Architecture Design (under continuous updating)
- 淘宝焦点图布局实战
- C # create self host webservice
- Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
- 会员积分营销系统操作的时候怎样提升消费者的积极性?
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
- 【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
- CSP date calculation
猜你喜欢
Introduction to robotframework (I) brief introduction and use
[ruoyi] enable Mini navigation bar
【指针训练——八道题】
Solution: attributeerror: 'STR' object has no attribute 'decode‘
CobaltStrike-4.4-K8修改版安装使用教程
C # create self host webservice
[pointer training - eight questions]
Yyds dry inventory comparison of several database storage engines
Is there a completely independent localization database technology
Modeling specifications: naming conventions
随机推荐
微服务注册与发现
JS regular filtering and adding image prefixes in rich text
Follow the mouse's angle and keyboard events
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
Summary of Bible story reading
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
A copy can also produce flowers
codeforces每日5题(均1700)-第六天
4. File modification
Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
有没有完全自主的国产化数据库技术
Large scale DDoS attacks take Myanmar offline
[network security interview question] - how to penetrate the test file directory through
建模规范:命名规范
技术分享 | undo 太大了怎么办
MySQL learning notes-10-tablespace recycling
Taobao focus map layout practice
故障分析 | MySQL 耗尽主机内存一例分析
07 singleton mode
Redis installation