当前位置:网站首页>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
边栏推荐
- 【若依(ruoyi)】ztree 自定义图标(iconSkin 属性)
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
- 深度解析链动2+1模式,颠覆传统卖货思维?
- [unity3d] GUI control
- Maturity of master data management (MDM)
- JS regular filtering and adding image prefixes in rich text
- Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
- Force buckle 146 LRU cache
- Universal crud interface
- MySQL learning notes-10-tablespace recycling
猜你喜欢
【若依(ruoyi)】启用迷你导航栏
codeforces每日5题(均1700)-第六天
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
解决:AttributeError: ‘str‘ object has no attribute ‘decode‘
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
随机推荐
Network Security Learning - Web vulnerabilities (Part 1)
2020.02.11
Redis cluster deployment based on redis5
主数据管理(MDM)的成熟度
Qt发布exe软件及修改exe应用程序图标
2.11 simulation summary
Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
Introduction to robotframework (III) Baidu search of webui automation
[network security interview question] - how to penetrate the test file directory through
MySQL learning notes-10-tablespace recycling
淘宝焦点图布局实战
【指针训练——八道题】
Force buckle 146 LRU cache
[ruoyi] enable Mini navigation bar
纯Qt版中国象棋:实现双人对战、人机对战及网络对战
C语言sizeof和strlen的区别
Li Kou today's question -729 My schedule I
Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
Briefly describe the implementation principle of redis cluster