当前位置:网站首页>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"}}}}}}}
边栏推荐
- 《opencv学习笔记》-- 分离颜色通道、多通道混合
- How can I open an account with new bonds? Is it safe
- 链接器 --- Linker
- 深度学习~11+高分疾病相关miRNA研究新视角
- Adjustment method of easynvr video platform equipment channel page display error
- Installation and operation of libuv
- "Meng Hua Lu" is about to have a grand finale. It's better to learn it first than to look ahead!
- 炒伦敦金短线稳定赚钱技巧?在哪里炒伦敦金安全靠谱?
- 电商红包雨是如何实现的?拿去面试用(典型高并发)
- [Architect (Part 41)] installation of server development and connection to redis database
猜你喜欢
【老卫搞机】090期:键盘?主机?全功能键盘主机!

GTEST from getting started to getting started

《梦华录》要大结局了,看超前点映不如先来学学它!

Axi low power interface

Insurance app aging service evaluation analysis 2022 issue 06

【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献

GLOG从入门到入门

How stupid of me to hire a bunch of programmers who can only "Google"!

New progress in the construction of meituan's Flink based real-time data warehouse platform
![[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
随机推荐
[redisson] analysis of semaphore lock source code
Single gene pan cancer + simple experiment can be published 7 points+
【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
Is it safe to open an account under the conditions of new bonds
Is GF Securities reliable? Is it safe to open a securities account?
AXI低功耗接口
Basic path test of software test on the function of the previous day
Jenkins performance test
LS-DYNA beginner's experience
《opencv学习笔记》-- 分离颜色通道、多通道混合
PF_ Ring ZC | high speed traffic processing dpdk alternative
Use go to process millions of requests per minute
Programmer: after 5 years in a company with comfortable environment, do you want to continue to cook frogs in warm water or change jobs?
Programmers spend most of their time not writing code, but...
[mysql_16] variables, process control and cursors
Coinbase将推出首个针对零售交易员的加密衍生产品
分布式系统解决之道:目录、消息队列、事务系统及其他
广发证券靠谱吗?开证券账户安全吗?
How to check the situation that the national standard platform easygbs equipment video cannot be accessed by grabbing packets?
嵌入式必学!硬件资源接口详解——基于ARM AM335X开发板 (上)