Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过使用构建名称的变量调用jenkins作业_Jenkins_Start Job - Fatal编程技术网

通过使用构建名称的变量调用jenkins作业

通过使用构建名称的变量调用jenkins作业,jenkins,start-job,Jenkins,Start Job,我尝试从参数化触发器启动作业,然后从给定变量计算名称。 是否可以在字段中设置: Build触发要构建的项目 像这样的值 ${RELEASE}-MAIN-${PROJECT}-LOAD\u START ?不幸的是,这在构建触发器中是不可能的。我为这个“高阶构建作业”寻找了一个解决方案,它允许您使用一个参数化构建插件创建一个动态构建名称,但我找不到 但是,使用,您可以做很多功能强大的事情。下面是一个脚本,可以修改它来执行您想要的操作。特别注意,它使用build.buildVariables.get(

我尝试从参数化触发器启动作业,然后从给定变量计算名称。 是否可以在字段中设置: Build触发要构建的项目 像这样的值 ${RELEASE}-MAIN-${PROJECT}-LOAD\u START


不幸的是,这在构建触发器中是不可能的。我为这个“高阶构建作业”寻找了一个解决方案,它允许您使用一个参数化构建插件创建一个动态构建名称,但我找不到

但是,使用,您可以做很多功能强大的事情。下面是一个脚本,可以修改它来执行您想要的操作。特别注意,它使用
build.buildVariables.get(“MY_ENV_VAR”)
获取环境变量。环境变量
TARGET\u BUILD\u JOB
指定要生成的生成作业的名称。在您的情况下,您可能希望使用以下两个环境变量构建
目标构建作业

build.buildVariables.get("RELEASE")
build.buildVariables.get("PROJECT")
对脚本进行了注释,因此如果您不熟悉基于Java的Groovy,它应该是有意义的

import hudson.model.*
import hudson.model.queue.*
import hudson.model.labels.*
import org.jvnet.jenkins.plugins.nodelabelparameter.*

def failBuild(msg)
{
     throw new RuntimeException("[GROOVY] User message, exiting with error: " + msg)
}

// Get the current build job
def thr = Thread.currentThread()
def build = thr?.executable

// Get the parameters for the current build job
// For ?:, see "Elvis Operator" (http://groovy.codehaus.org/Operators#Operators-ElvisOperator)
def currentParameters = build.getAction(ParametersAction.class)?.getParameters() ?: 
    failBuild("There are no parameters to pass down.")

def nodeName = build.getBuiltOnStr()
def newParameters = new ArrayList(currentParameters); newParameters << new NodeParameterValue("param_NODE", 
    "Target node -- the node of the previous job", nodeName)

// Retrieve information about the target build job
def targetJobName = build.buildVariables.get("TARGET_BUILD_JOB")
def targetJobObject = Hudson.instance.getItem(targetJobName) ?: 
    failBuild("Could not find a build job with the name $targetJobName. (Are you sure the spelling is correct?)")
println("$targetJobObject, $targetJobName")
def buildNumber = targetJobObject.getNextBuildNumber()

// Add information about downstream job to log
def jobUrl = targetJobObject.getAbsoluteUrl()
println("Starting downstream job $targetJobName ($jobUrl)" +  "\n")
println("======= DOWNSTREAM PARAMETERS =======")
println("$newParameters")

// Start the downstream build job if this build job was successful
boolean targetBuildQueued = targetJobObject.scheduleBuild(5,
      new Cause.UpstreamCause(build),
      new ParametersAction(newParameters)
    );

if (targetBuildQueued)
{
    println("Build started successfully")
    println("Console (wait a few seconds before clicking): $jobUrl/$buildNumber/console")
}
else
    failBuild("Could not start target build job")
导入hudson.model*
导入hudson.model.queue*
导入hudson.model.labels*
导入org.jvnet.jenkins.plugins.nodelabelparameter*
def故障生成(msg)
{
抛出新的RuntimeException(“[GROOVY]用户消息,退出时出现错误:“%msg”)
}
//获取当前生成作业
def thr=Thread.currentThread()
def build=thr?可执行文件
//获取当前生成作业的参数
//有关?:,请参阅“Elvis操作员”(http://groovy.codehaus.org/Operators#Operators-ELV(等参器)
def currentParameters=build.getAction(ParametersAction.class)?.getParameters()
failBuild(“没有要传递的参数”)
def nodeName=build.getBuiltOnStr()
def newParameters=新阵列列表(currentParameters);新参数