“Groovy”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
→‎ins
→‎map
 
(未显示同一用户的18个中间版本)
第1行: 第1行:
[[category:ops]]  
+
[[category:ops]] [[category:devops]]  
=ins=
+
=install=
 
  sudo apt install  groovy groovy-doc  #Groovy Version: 2.4.21 JVM: 11.0.8 Vendor: Debian OS: Linux
 
  sudo apt install  groovy groovy-doc  #Groovy Version: 2.4.21 JVM: 11.0.8 Vendor: Debian OS: Linux
  
 
https://www.osradar.com/install-apache-groovy-ubuntu-debian/
 
https://www.osradar.com/install-apache-groovy-ubuntu-debian/
  
 +
=usage=
 +
当然也可以直接创建.groovy文件用命令行直接运行。
 +
 +
[https://www.qikqiak.com/post/groovy-simple-tutorial/ Groovy 简明教程]
 +
==hello world==
 +
<pre>
 +
emacs    e.groovy
 +
class Example {
 +
  static void main(String[] args) {
 +
      // Using a simple println statement to print output to the console
 +
      println('Hello World');
 +
  }
 +
}
 +
 +
 +
groovy  e.groovy
 +
 +
Hello World</pre>
 +
 +
==注释annotations==
 +
多行注释
 +
 +
多行注释以/*开头,并且能在行的任何位置 。以/*开头,包括新的行,直到第一个*/结束都被认为是注释的部分。多行注释可以放于声明的开始或者声明的中间。
 +
 +
[https://www.w3cschool.cn/groovy/groovy_annotations.html Groovy 注释]
 +
 +
==call==
 +
<pre>
 +
def call(Map config) 是 Groovy 语言中定义一个名为 call 的函数的语法。下面是对这部分的详细解释:
 +
关键点
 +
 +
    def:这是 Groovy 中定义变量或函数的关键字,表示定义一个新的函数。
 +
 +
    call:这是函数的名称。在 Groovy 中,特别是在 Jenkins Pipeline 中,如果一个类或脚本重写了 call 方法,可以让这个类的实例像函数一样被调用。
 +
 +
    Map config:这是函数的参数,表示传入一个类型为 Map 的参数。Map 是一种键值对集合,可以存储各种配置选项。在这里,config 可能包含多个配置项,比如节点、分支、凭证 ID 等。
 +
 +
用法示例
 +
 +
在 Jenkins Pipeline 中,这样的函数通常会被用来封装一些常见的操作,例如拉取代码、构建、测试等。调用时,可以传入一个 Map,例如:
 +
 +
groovy
 +
 +
call([
 +
    node: "my-node",
 +
    branch: "main",
 +
    credentialsId: "my-credentials",
 +
    gitURL: "https://github.com/my-repo.git"
 +
])
 +
 +
在这个示例中,call 函数会使用传入的配置来执行相应的操作。
 +
总结
 +
 +
def call(Map config) 定义了一个函数,该函数可以接收一个包含多个配置项的 Map 作为参数,并在函数内部使用这些配置来执行一系列操作。这种结构使得代码更加灵活和模块化。
 +
 +
from chatgpt
 +
</pre>
 +
==map==
 +
<pre>
 +
evan@myxps:~/tmp$ cat 2.groovy
 +
def  http=[:]
 +
println http.size()
 +
http['syn'] = 'helo'
 +
println http['syn']
 +
println http.size()
 +
 +
</pre>
 +
 +
https://www.cnblogs.com/jyan/archive/2012/05/30/2526372.html
 +
 +
 +
[https://blog.csdn.net/dora_310/article/details/52877750  Groovy集合(map)]
 +
 +
==Groovy函数调用 ==
 +
 +
[https://blog.csdn.net/qfanmingyiq/article/details/106028568  Groovy函数调用]
 +
 +
 +
[https://iowiki.com/groovy/groovy_methods.html Groovy - 方法(Methods)]
 +
 +
=jenkins and groovy =
 +
 +
[https://blog.csdn.net/gzh8579/article/details/59522469 Jenkins插件groovy-postbuild使用(一)-获取jenkins环境变量值和获取build结果]
 
=see also=
 
=see also=
 +
[https://www.qikqiak.com/post/groovy-simple-tutorial/ Groovy 简明教程]
 +
 +
 +
[https://www.w3cschool.cn/groovy/ Groovy 教程]
 +
 +
[https://www.jianshu.com/p/e8dec95c4326 Groovy 语言快速入门]
 +
 +
[https://www.jianshu.com/p/2c6b95097b2c Groovy简介与使用]
 +
 
[https://www.zhihu.com/question/22870020 为什么Groovy语言火不起来?]
 
[https://www.zhihu.com/question/22870020 为什么Groovy语言火不起来?]
 +
 +
[https://blog.csdn.net/cyh1111/article/details/4128062  Groovy是什么?]

2024年9月24日 (二) 15:49的最新版本

install

sudo apt install  groovy groovy-doc  #Groovy Version: 2.4.21 JVM: 11.0.8 Vendor: Debian OS: Linux

https://www.osradar.com/install-apache-groovy-ubuntu-debian/

usage

当然也可以直接创建.groovy文件用命令行直接运行。

Groovy 简明教程

hello world

emacs    e.groovy
class Example {
   static void main(String[] args) {
      // Using a simple println statement to print output to the console
      println('Hello World');
   }
}


groovy  e.groovy

Hello World

注释annotations

多行注释 

多行注释以/*开头,并且能在行的任何位置 。以/*开头,包括新的行,直到第一个*/结束都被认为是注释的部分。多行注释可以放于声明的开始或者声明的中间。

Groovy 注释

call

def call(Map config) 是 Groovy 语言中定义一个名为 call 的函数的语法。下面是对这部分的详细解释:
关键点

    def:这是 Groovy 中定义变量或函数的关键字,表示定义一个新的函数。

    call:这是函数的名称。在 Groovy 中,特别是在 Jenkins Pipeline 中,如果一个类或脚本重写了 call 方法,可以让这个类的实例像函数一样被调用。

    Map config:这是函数的参数,表示传入一个类型为 Map 的参数。Map 是一种键值对集合,可以存储各种配置选项。在这里,config 可能包含多个配置项,比如节点、分支、凭证 ID 等。

用法示例

在 Jenkins Pipeline 中,这样的函数通常会被用来封装一些常见的操作,例如拉取代码、构建、测试等。调用时,可以传入一个 Map,例如:

groovy

call([
    node: "my-node",
    branch: "main",
    credentialsId: "my-credentials",
    gitURL: "https://github.com/my-repo.git"
])

在这个示例中,call 函数会使用传入的配置来执行相应的操作。
总结

def call(Map config) 定义了一个函数,该函数可以接收一个包含多个配置项的 Map 作为参数,并在函数内部使用这些配置来执行一系列操作。这种结构使得代码更加灵活和模块化。

from chatgpt

map

evan@myxps:~/tmp$ cat 2.groovy 
def  http=[:]
println http.size()
http['syn'] = 'helo'
println http['syn']
println http.size()

https://www.cnblogs.com/jyan/archive/2012/05/30/2526372.html


Groovy集合(map)

Groovy函数调用

Groovy函数调用


Groovy - 方法(Methods)

jenkins and groovy

Jenkins插件groovy-postbuild使用(一)-获取jenkins环境变量值和获取build结果

see also

Groovy 简明教程


Groovy 教程

Groovy 语言快速入门

Groovy简介与使用

为什么Groovy语言火不起来?

Groovy是什么?