admin管理员组

文章数量:1418380

I have a Jenkins FreeStyle Project with choice parameter called "PROJECT".

In extensible choice parameter "OPTIONS" I want to load list of options from one of files depending on passed $PROJECT value (for example, if $PROJECT == "Project_A", then parameter "OPTIONS" should return options from "/var/lib/jenkins/files/Project_A.txt"). I use this Groovy script:

import hudson.model.*

// Get current thread / Executor
def thr = Thread.currentThread()

// Get current build and extract PROJECT value
def build = thr?.executable
def resolver = build.buildVariableResolver
def project = resolver.resolve("PROJECT")

// Construct the file path
def filePath = "/var/lib/jenkins/files/${project}.txt"
def file = new File(filePath)

// Read options
def options = []
file.eachLine { line ->
    line = line.trim()
    options.add(line)
}

// Return list of options
return options

But when I try to start a build there is no drop-down with options even though file contain values. Also I don't know how to debug since running script in Sand-box or in ScriptConsole returns

groovy.lang.MissingPropertyException: No such field found: field java.lang.Thread executable

What should be the correct Groovy script to extract "PROJECT" parameter value?

本文标签: jenkinsHow to access build Parameter value from Groovy scriptStack Overflow