我们将build-pipeline-plugin用于类似的事情,我们所做的是提供一个 groovy 脚本,用于存储要传递给下游项目的运行时构建信息:
有点冗长,因为我们包含下游构建的 SVN 信息:
import hudson.model.*
def thr = Thread.currentThread()
def build = thr?.executable
def workspace = build.getWorkspace()
def ant = new AntBuilder()
ant.exec(executable: "svn", outputproperty: "output", dir: workspace){
arg(line: "info")
}
svnInfo = ant.project.getProperty("output")
print svnInfo
def pattern = /Last\s+Changed\s+Author:\s+(\w+)/
def matcher = (svnInfo =~ pattern)
def user = matcher[0][1]
def langs = new XmlParser().parseText(build.getParent().getWorkspace().child('pom.xml').readToString())
def appVer = langs.properties.release.text()
def artifactId = langs.artifactId.text()
def params = [
new StringParameterValue('PL_SVN_REVISION', build.getEnvVars()['SVN_REVISION']),
new StringParameterValue('PL_BUILD_NUMBER', build.getEnvVars()['BUILD_NUMBER']),
new StringParameterValue('PL_APP_NAME', 'FooApp'),
new StringParameterValue('PL_COMMITTER_NAME',user ),
new StringParameterValue('PL_APP_VERSION',appVer),
new StringParameterValue('PL_ARTIFACT_ID',artifactId)
]
build.addAction(new ParametersAction(params))
然后在下游构建中,它们应该像这样可用:
示例 1,设置构建名称输入:
#${BUILD_NUMBER} - ${ENV,var="PL_APP_NAME"} - ${ENV,var="PL_APP_VERSION"} - ${ENV,var="PL_SVN_REVISION"}
示例 2,调用 Ant目标输入:
deploy
-Denvironment=ONT-base
-DWAR-LOCATION=%war-repo%/%PL_APP_NAME%/%PL_BUILD_NUMBER%-%PL_SVN_REVISION%/
-DWAR-NAME=%PL_ARTIFACT_ID%-%PL_APP_VERSION%.%PL_BUILD_NUMBER%-%PL_SVN_REVISION%.war
但是请注意,当在多个上游项目中重用下游项目时,存在一个未正确传递变量的突出错误。