当前位置:网站首页>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 

原网站

版权声明
本文为[weixin_ thirty-nine million four hundred and thirty thousand fi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202132347278728.html