我想知道是否可以将jenkins管道作业中的变量定义传递给已加载的脚本。 加载的脚本
管道作业
node {
// Some declaration and code
stage('Prepare deploy') {
// Create a talbe for the servers lists
def servers = [:]
// For each server know, if deployment is enabled
// deploy resources
params.each { srv, value ->
if ("$value" == "true"){
// add the current current to the enabled servers
servers["Server ${srv}"] = {
// Define specific variable
String SERVER=props."SRV_${srv}"
String CONF=env.DEPLOY_HOME + "/${srv}"
// Install server - the SERVER and CONF variable need to be propagate to the others scripts
load env.JENKINSFILES_DIRECTORY + "/server-configuration"
load env.JENKINSFILES_DIRECTORY + "/server-deploiement"
load env.JENKINSFILES_DIRECTORY + "/server-postconfig"
load env.JENKINSFILES_DIRECTORY + "/server-start"
}
}
}
parallel servers
}
}
服务器配置文件
#!/usr/bin/env groovy
node{
// Some declaration
stage('configure serveur'){
// The variable SERVER and CONF must be visible here
// is it possible ?
sh "ssh -X " + env.USER +"@${SERVER} 'sh echo \"${CONF}\"'"
}
}
谢谢
答案 0 :(得分:1)
BehaviorSubject
是您要寻找的
next
服务器配置
withEnv