当前位置:网站首页>pipeline groovy
pipeline groovy
2022-06-24 12:23:00 【Chen Bucheng I】
One . Variable
1. Direct definition
def x="abc"
2. Assign a variable to the result from the script execution branch = “/jen_script/return-branch.sh $group $job”.execute().text
# Separate the results by commas , Write to array branch = “one, two, three” branch_list = branch[1..-2].tokenize(‘,’)
3. quotes```pythondef x="abc"print '${x}' // Output ${x}, Variable not supportedprint "${x}" // Output abc, Support variablesprint ''' // Output ${X}, Variable not supported${X}'''print """ // Output abc, Support variables${X}"""
Two . Process judgment
1. Judgment variable
if(x='abc'){echo "abc"}else(x='bcd'){echo "bcd"}
3、 ... and . Method
1. Define the method and call
/String Is to declare that this variable should be of type string , It can be omitted , The type changes according to the incoming typedef createName(String givenName,String familyName){return givenName +""+ familyName}// call , Parentheses may be omittedcreateName(familyName ="Lee", givenName ="Bruce")
2. Method to add default parameters
def sayHello(String name ="zhangsan"){print"hello ${name}"}// Parentheses cannot be omitted when parameters are not passedsayHello()
3. Closure
// Define closuredef codeBlock ={print"hello closure"}// Closures can also be used directly as function callscodeBlock()// Output hello closure
4. The closure is passed as a parameter to another method
// Define closuredef codeBlock ={print"hello closure"}// Define a method , It takes a closure parameterdef sayHello(closure){closure()}// Calling sayHello Method can be as followssayHello(codeBlock)// If you remove the statement defined by the closuresayHello({print"hello closure"})// Because parentheses are not necessary , thereforesayHello {print"hello closure"}// If sayHello Change the name to pipeine Namely , Is it very similar jenkins Of pipelinepipeline {print"hello closure"}
5. Alternative use of closures , Define a stage Method
// Define methods , Pass a normal variable and a closuredef stage(String name, closue){print nameclosue()}// Under normal circumstances , Use this way stage functionstage("stage name",{print"closure"})// Execution printing//stage name//closure// It can be written in another waystage("stage name"){print"closure"}
Four . Array
1. Define an array , Then determine whether it is in the array . For example, judgment two Whether in one In this array , You need to define the string first , Back cut .
ipeline {agent anyenvironment {one ="xxx,ddd,lll"two ="ddd"}stages {stage('pull'){steps {script {list = one.split(',')for( i in list ){echo "$i"echo "$two"if(i == two){echo "ok two"}else{echo "no two"}}}}}}}
边栏推荐
- 【云驻共创】解读HarmonyOS 应用与服务生态
- 【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
- The idea of "6 points + gene family" without experiment~
- LS-DYNA新手入门经验
- Axi low power interface
- How is the e-commerce red envelope realized? For interview (typical high concurrency)
- Difference between X12 830 and 862 messages
- QT -- the qtabwidget supports dragging tabbar items
- Identification of new prognostic DNA methylation features in uveal melanoma by 11+ based on methylation group and transcriptome analysis~
- Opencv learning notes - loading and saving images
猜你喜欢

Programmers spend most of their time not writing code, but...

ArrayList#subList这四个坑,一不小心就中招
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!

如何优雅的写 Controller 层代码?

Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!

Opencv learning notes -- Separation of color channels and multi-channel mixing

《opencv学习笔记》-- 感兴趣区域(ROI)、图像混合

GTest从入门到入门

How to write controller layer code gracefully?
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/7a/16b481753d7d57f50dc8787eec8a1a.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
随机推荐
Cluster control management
How stupid of me to hire a bunch of programmers who can only "Google"!
Concentrate on research preparation, Tencent cloud, see you next year!
How does easygbs, a national standard platform, solve the problem that information cannot be carried across domains?
11+! Methylation modification patterns based on m6A regulatory factors in colon cancer are characterized by different tumor microenvironment immune spectra
Adjustment method of easynvr video platform equipment channel page display error
《opencv学习笔记》-- 离散傅里叶变换
How can a shell script (.Sh file) not automatically close or flash back after execution?
Ingenious conception - iron death regulatory factor classification and prognosis 6+
分布式系统解决之道:目录、消息队列、事务系统及其他
Speculation London gold short-term stable money making skills? Where is it safe to fry London gold?
广发证券靠谱吗?开证券账户安全吗?
LS-DYNA beginner's experience
Opencv learning notes - loading and saving images
11+! 结肠癌中基于 m6A 调节因子的甲基化修饰模式以不同的肿瘤微环境免疫谱为特征
Installation and operation of libuv
Fizz gateway secondary development integration tutorial
如何优雅的写 Controller 层代码?
11+文章-机器学习打造ProTICS框架-深度揭示了不同分子亚型中肿瘤浸润免疫细胞对预后的影响
Embedded must learn! Detailed explanation of hardware resource interface - based on arm am335x development board (Part 2)