I have a Jenkins Job that is running some gradle task:
gradle clean -Pendpoint=qab assembleFromJenkinsJob
Here is the task itself:
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
}
The task assembleFromJenkinsJob
is running:
:app:assembleFromJenkinsJob
Value of 'endpoint': qab
but assembleJenkinsQa
or assembleRelease
are not running.
I even tried to do it like this assembleRelease.execute()
but nothing is happening.
You should never call a task directly. Also you don't need to call a task but rather define a dependency. And, finally, in an action ( <<
) it's too late for running a task.
Let me know it this works:
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
}
I would advice the use of 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'
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.