当前位置:网站首页>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
```python
def x="abc"
print '${x}' // Output ${x}, Variable not supported
print "${x}" // Output abc, Support variables
print ''' // 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 type
def createName(String givenName,
String familyName){
return givenName +
""
+ familyName
}
// call , Parentheses may be omitted
createName(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 passed
sayHello()
3. Closure
// Define closure
def codeBlock =
{print
"hello closure"}
// Closures can also be used directly as function calls
codeBlock()
// Output hello closure
4. The closure is passed as a parameter to another method
// Define closure
def codeBlock =
{print
"hello closure"}
// Define a method , It takes a closure parameter
def sayHello(closure)
{
closure()
}
// Calling sayHello Method can be as follows
sayHello(codeBlock)
// If you remove the statement defined by the closure
sayHello(
{print
"hello closure"}
)
// Because parentheses are not necessary , therefore
sayHello {
print
"hello closure"
}
// If sayHello Change the name to pipeine Namely , Is it very similar jenkins Of pipeline
pipeline {
print
"hello closure"
}
5. Alternative use of closures , Define a stage Method
// Define methods , Pass a normal variable and a closure
def stage(String name, closue)
{
print name
closue()
}
// Under normal circumstances , Use this way stage function
stage("stage name",
{print
"closure"})
// Execution printing
//stage name
//closure
// It can be written in another way
stage("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 any
environment {
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"
}
}
}
}
}
}
}
边栏推荐
- GTEST from getting started to getting started
- u盘安装kali并且持久化
- About the unsupported instruction set SSE 4.2 of CPU in virtualization
- Opencv learning notes - regions of interest (ROI) and image blending
- Deep learning ~11+ a new perspective on disease-related miRNA research
- The solution of distributed system: directory, message queue, transaction system and others
- Based on am335x development board arm cortex-a8 -- acontis EtherCAT master station development case
- How does easygbs, a national standard platform, solve the problem that information cannot be carried across domains?
- Linker --- linker
- What are the low threshold financial products in 2022? Not much money
猜你喜欢
《opencv学习笔记》-- 分离颜色通道、多通道混合
ArrayList#subList这四个坑,一不小心就中招
GLOG从入门到入门
我真傻,招了一堆只会“谷歌”的程序员!
How can a shell script (.Sh file) not automatically close or flash back after execution?
AXI低功耗接口
Opencv learning notes - loading and saving images
Database migration tool flyway vs liquibase (II)
u盘安装kali并且持久化
Installation and operation of libuv
随机推荐
Opencv learning notes - regions of interest (ROI) and image blending
How can a shell script (.Sh file) not automatically close or flash back after execution?
不用做实验的6分+基因家族纯生信思路~
Linker --- linker
【云驻共创】解读HarmonyOS 应用与服务生态
嵌入式必学!硬件资源接口详解——基于ARM AM335X开发板 (上)
5W1H talk about open source - what is open source?
VaR in PHP_ export、print_ r、var_ Differences in dump debugging
嵌入式必学!硬件资源接口详解——基于ARM AM335X开发板 (下)
The latest hot spot: the use of copper death related genes for tumor prognosis typing!
计组-总复习
Insurance app aging service evaluation analysis 2022 issue 06
如何优雅的写 Controller 层代码?
9+! Predicting lymph node status from histology of colorectal cancer by deep learning
2021-06-03: Boolean operation. Given a Boolean expression and an expected cloth
Programmer: after 5 years in a company with comfortable environment, do you want to continue to cook frogs in warm water or change jobs?
What code did the full stack programmer write this month?
[Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!
Tools and methods - use code formatting tools in source insight
11+! 结肠癌中基于 m6A 调节因子的甲基化修饰模式以不同的肿瘤微环境免疫谱为特征