栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Jenkins中的Pipeline插件在Jenkinsfile中调用Java函数

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Jenkins中的Pipeline插件在Jenkinsfile中调用Java函数

您可以将逻辑编写在Groovy文件中,该文件可以保存在Git存储库,管道共享库或其他地方。

例如,如果您

utils.groovy
的存储库中有文件:

List<Integer> myNumbers() {  return [1, 2, 3, 4, 5]}return this

在您的中

Jenkinsfile
,您可以通过以下
load
步骤使用它:

def utilsnode {  // Check out repository with utils.groovy  git 'https://github.com/…/my-repo.git'  // Load definitions from repo  utils = load 'utils.groovy'}// Execute utility methoddef numbers = utils.myNumbers()// Do stuff with `numbers`…

另外,您可以签出Java代码并运行它,然后捕获输出。然后,您可以将其解析为列表,或稍后在管道中所需的任何数据结构。例如:

node {  // Check out and build the Java tool    git 'https://github.com/…/some-java-tools.git'  sh './gradlew assemble'  // Run the compiled Java tool  def output = sh script: 'java -jar build/output/my-tool.jar', returnStdout: true  // Do some parsing in Groovy to turn the output into a list  def numbers = parseOutput(output)  // Do stuff with `numbers`…}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373625.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号