我为此问题进行了大量搜索,但找不到任何可行的解决方案。有人可以帮我吗?我想通过jenkins脚本控制台获取已经存在的env vars值。
答案 0 :(得分:0)
您需要区分:
def myVar = build.getBuildVariables().get('myVar')
System.getenv('MY_VARIABLE')
如果看到
groovy.lang.MissingPropertyException: No such property: manager for class: Script1
选中this answer,然后首先定义build
:
import hudson.model.*
def build = Thread.currentThread().executable
def buildNumber = build.number
答案 1 :(得分:0)
根据this answer,为了从Jenkins脚本控制台访问env var,请执行以下操作:
import jenkins.model.*;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.EnvVars;
jenkins = Jenkins.instance;
EnvironmentVariablesNodeProperty prop = jenkins.getGlobalNodeProperties().get(EnvironmentVariablesNodeProperty.class)
EnvVars env = prop.getEnvVars()
def myVariable = env['MY_VAR']
http://<JENKINS_URL>/env-vars.html
中列出的环境变量可用于每个版本。为了在Jenkins脚本控制台中访问这些变量,您需要首先定义build:
build = Jenkins.instance.getItemByFullName('JOB_NAME').getBuildByNumber(BUILD_NUMBER)
envvars = build.getEnvironment()
envvars.each{envvar ->
println envvar
}