如何在命令行中定义gradle中的teamcity ['build.number']属性 [英] How can I define the teamcity['build.number'] property in gradle from command line

查看:695
本文介绍了如何在命令行中定义gradle中的teamcity ['build.number']属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从命令行定义teamcity ['build.number']属性?我尝试-Pteamcity.build.number = 1但它不工作。

Is there a way to define teamcity['build.number'] property from command line? I tried -Pteamcity.build.number=1 but it didn't work.

我有一个build.gradle文件与此任务:

I have a build.gradle file with this task in it:

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命令给我们一个错误:

It works on the build server, but it drives all the developers crazy, because we don't have teamcity installed on our machines, and any gradle command gives us an error:

$ 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


推荐答案

你所描述的场景 - 允许开发人员在他们的本地机器上运行一个build,这也需要在TeamCity中运行 - 我发现这对我有用(TeamCity 7):

Given the scenario you describe - allowing developers to run a build on their local machine which also needs to run in TeamCity - I found this worked for me (TeamCity 7):

if (hasProperty("teamcity")) {
  version = teamcity["build.number"]
} else {
  version = '0.0-beta'
}

默认情况下,gradle生成的jar文件会自动使用'version' 。因此,使用build.gradle文件中的代码,开发人员构建将具有用0.0-beta标记的工件,并且同一项目的TeamCity构建拾取TeamCity构建号。

By default the gradle produced jar files will automatically use 'version' in their name. So with this code in the build.gradle file, developer builds will have artifacts tagged with '0.0-beta' and TeamCity builds of the same project pick up the TeamCity build number.

但是,如果你想,例如,添加信息到清单你会做类似:

But if you want to, for instance, add information to the manifest you'll do something like:

jar {
  manifest {
    attributes 'Implementation-Title': rootProject.name, 'Implementation-Version': version
  }
}

我希望有帮助吗?

这篇关于如何在命令行中定义gradle中的teamcity ['build.number']属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆