有没有办法从命令行定义 teamcity['build.number'] 属性?我试过 -Pteamcity.build.number=1 但没有用。
我有一个包含此任务的 build.gradle 文件:
distTar {
baseName = project.name+'.'+
project.version+'.'+
System.getProperty("system.rnf.brach_name")+'.'+
teamcity['build.number']+'.'+
teamcity['build.vcs.number.1']
archiveName = baseName+'.tar'
into(baseName) {
from '.'
include 'config/*'
include 'run-script/*.sh'
}
}
它适用于构建服务器,但它让所有开发人员都发疯了,因为我们的机器上没有安装 teamcity,并且任何 gradle 命令都会给我们一个错误:
$ gradle tasks
FAILURE: Build failed with an exception.
* Where:
Build file '/home/me/work/myproject/build.gradle' line: 31
* What went wrong:
A problem occurred evaluating root project 'myproject'.
> Could not find property 'teamcity' on task ':MyProject:distTar'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
最佳答案
鉴于您描述的场景 - 允许开发人员在他们的本地机器上运行构建,这也需要在 TeamCity 中运行 - 我发现这对我有用(TeamCity 7):
if (hasProperty("teamcity")) {
version = teamcity["build.number"]
} else {
version = '0.0-beta'
}
默认情况下,gradle 生成的 jar 文件将自动在其名称中使用“版本”。因此,使用 build.gradle 文件中的此代码,开发人员构建将具有标记为“0.0-beta”的工件,并且同一项目的 TeamCity 构建将获取 TeamCity 构建号。
但是,例如,如果您想向 list 添加信息,您将执行以下操作:
jar {
manifest {
attributes 'Implementation-Title': rootProject.name, 'Implementation-Version': version
}
}
我希望这有帮助吗?
关于command-line - 如何从命令行定义 gradle 中的 teamcity ['build.number' ] 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20189846/