3
我嘗試從參數化觸發器啓動作業,然後計算給定變量的名稱。 是否有可能在現場設置: 生成觸發器項目建設 這樣 $ {RELEASE} - 主要價值 - $(項目)-LOAD_START通過使用變量調用jenkins作業來創建名稱
?
我嘗試從參數化觸發器啓動作業,然後計算給定變量的名稱。 是否有可能在現場設置: 生成觸發器項目建設 這樣 $ {RELEASE} - 主要價值 - $(項目)-LOAD_START通過使用變量調用jenkins作業來創建名稱
?
不幸的是,這對於構建觸發器來說是不可能的。我尋找這個「高階構建作業」的解決方案,它可以讓你用一個參數化的構建插件創建一個動態構建名稱,但是我找不到一個。
但是,使用Groovy Postbuild Plugin,你可以做很多強大的事情。下面是一個腳本,可以進行修改以執行您想要的操作。尤其要注意的是,它使用build.buildVariables.get("MY_ENV_VAR")
來獲取環境變量。環境變量TARGET_BUILD_JOB
指定要構建的構建作業的名稱。在你的情況,你會希望使用這兩個環境變量來構建TARGET_BUILD_JOB
:
build.buildVariables.get("RELEASE")
build.buildVariables.get("PROJECT")
的腳本註釋,這樣,如果你不熟悉使用Groovy,它是基於Java的關閉,它應該有希望有意義!
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")