我有一个执行某些gradle任务的Jenkins Job:
gradle clean -Pendpoint=qab assembleFromJenkinsJob
这是任务本身:
task assembleFromJenkinsJob << {
logger.lifecycle("Value of 'endpoint': ${endpoint}")
if (String.valueOf(endpoint).equalsIgnoreCase('qab')) {
assembleJenkinsQa
} else if (String.valueOf(endpoint).equalsIgnoreCase('prod')) {
assembleRelease
}
else
assembleJenkinsQa
}
任务assembleFromJenkinsJob
正在运行:
:app:assembleFromJenkinsJob
Value of 'endpoint': qab
但是assembleJenkinsQa
或assembleRelease
没有运行。
我什至试图这样做assembleRelease.execute()
但什么也没发生。
答案 0 :(得分:2)
永远不要直接调用任务。另外,您不需要调用任务,而是定义一个依赖项。最后,在 action (<<
)中,运行任务为时已晚。
让我知道这可行:
task assembleFromJenkinsJob {
logger.lifecycle("Value of 'endpoint': ${endpoint}")
if (String.valueOf(endpoint).equalsIgnoreCase('qab')) {
dependsOn assembleJenkinsQa
} else if (String.valueOf(endpoint).equalsIgnoreCase('prod')) {
dependsOn assembleRelease
} else
dependsOn assembleJenkinsQa
}
答案 1 :(得分:1)
我建议您使用finalizedBy
task assembleFromJenkinsJob {
def ep = String.valueOf(endpoint).toLowerCase()
logger.lifecycle("Value of 'endpoint': ${ep}")
switch (ep) {
case 'qab':
finalizedBy 'assembleJenkinsQa'
break
case 'prod':
finalizedBy 'assembleRelease'
break
default:
finalizedBy 'assembleJenkinsQa'
}
}