首页 > 解决方案 > 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')

在插件中的控制台内进行了测试,但仍然无法正常工作,有什么解决方案吗?

标签: jenkinsgroovypluginsjenkins-scriptler

解决方案


推荐阅读