jenkins - Jenkins:从 groovy 脚本中获取构建参数
问题描述
我有一个名为文本参数的工作,LOCAL_IP
然后我使用可扩展选择参数插件插入 Groovy 脚本,我试图获取LOCAL_IP
参数但没有成功,有人知道我做错了什么吗?这是我的代码:
import hudson.model.*
def build = this.getProperty(‘binding’).getVariable(‘build’)
def listener = this.getProperty(‘binding’).getVariable(‘listener’)
def env = build.getEnvironment(listener)
return env.LOCAL_IP
收到此错误自动取款机:
startup failed:
Script1.groovy: 3: Invalid variable name. Must start with a letter but was: ‘binding’
. At [3:30] @ line 3, column 30.
def build = this.getProperty(‘binding’).getVariable(‘build’)
^
1 error
我已经阅读了页面末尾来自https://wiki.jenkins.io/display/JENKINS/Groovy+plugin的文档,并尝试了他们所说的但没有结果:
import hudson.model.*
import hudson.AbortException
import hudson.console.HyperlinkNote
import java.util.concurrent.CancellationException
// Retrieve parameters of the current build
def foo = build.buildVariableResolver.resolve("FOO")
println "FOO=$foo"
并且
System.getProperty('FOO')
在插件中的控制台内进行了测试,但仍然无法正常工作,有什么解决方案吗?
解决方案
推荐阅读
- apache-nifi - Nifi HandleHttpResponse 八位字节流到 JSON 内容类型
- git - 如何为 Maven 模块创建单独的 Bamboo 计划?
- algorithm - 寻找最佳往返机票组合
- c# - 在 LINQ 中选择不属于某个用户但属于其他用户的所有项目
- react-intl - React-Intl 复数消息获取错误
- javascript - 如何检测页面上任何位置的任何键盘输入
- angular - 带有 api-ai-javascript@2.0.0-beta.21 的 Angular 8 Dialogflow catbot 未在 IE 11 上加载
- javascript - Discord.js:从所有渠道获取消息
- c++ - Directx12 和击键
- maven - 在没有插件的情况下将 Jenkins 与 Maven 集成