jenkins 调用java程序_如何使用Jenkins中的Pipeline插件在Jenkinsfile中调用Java函数

小编典典

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

例如,如果您utils.groovy的存储库中有文件:

List myNumbers() {

return [1, 2, 3, 4, 5]

}

return this

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

def utils

node {

// Check out repository with utils.groovy

git 'https://github.com/…/my-repo.git'

// Load definitions from repo

utils = load 'utils.groovy'

}

// Execute utility method

def 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`…

}

2020-07-25

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值