如何创建动态设置App Engine项目ID并运行appengineDeploy
任务的任务?
在此示例中,当我运行deployStaging
appengineDeploy
与项目'a'一起执行时,如何重写此代码以使其与项目'b'一起运行?
buildscript {
dependencies {
classpath("com.google.cloud.tools:appengine-gradle-plugin:2.0.1")
}
}
apply plugin: 'com.google.cloud.tools.appengine'
def gcpProject = 'a'
appengine {
deploy {
projectId = gcpProject
}
}
task deployStaging() {
doLast {
gcpProject = 'b'
}
}
deployStaging.finalizedBy appengineDeploy
答案 0 :(得分:0)
如何使用https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html代替呢?可以通过-P
命令行参数传递项目属性:
buildscript {
dependencies {
classpath("com.google.cloud.tools:appengine-gradle-plugin:2.0.1")
}
}
apply plugin: 'com.google.cloud.tools.appengine'
def gcpProject = project.findProperty('stageName') ?: 'a'
appengine {
deploy {
projectId = gcpProject
}
}
现在,如果您仅调用./gradlew appengineDeploy
,则gcpProject
变量将具有值'a'。如果您调用./gradlew appengineDeploy -PstageName=b
,则gcpProject
变量的值将为'b'。
答案 1 :(得分:0)
gradle插件伙计们提供的答案:
appengine {
deploy {
version = "123"
// do not define projectId here
}
}
task deployStaging {
dependsOn appengineDeploy
}
task deployProduction {
dependsOn appengineDeploy
}
// here's the weird gradle logic, use at your own risk
if (project.gradle.startParameter.taskNames.contains("deployStaging")) {
appengine.deploy.projectId = "potato-stage"
}
else if(project.gradle.startParameter.taskNames.contains("deployProduction")) {
appengine.deploy.projectId = "tomato-prod"
}