gpt4 book ai didi

gradle - TeamCity-如何在Gradle中访问环境变量

转载 作者:行者123 更新时间:2023-12-03 05:02:24 25 4
gpt4 key购买 nike

我在构建代理中指定了名为DIR的环境变量。它在“构建代理”属性的“参数/环境变量”部分中可见。我想从gradle访问此变量。我不知道我尝试了很多事情,例如:

if (project.hasProperty("teamcity")) {

println teamcity
println teamcity["teamcity.build.properties.file"]
def properties = file(teamcity["teamcity.build.properties.file"])
println properties.DIR
println DIR
println env.DIR
}

我的teamcity文件如下所示:
{teamcity.buildType.id=Taxi5Mobile_BuildDev, build.vcs.number.Taxi5Mobile_Taxi5devVCS=a23e58c8ff92, teamcity.version=8.1.1 (build 29939), teamcity.buildConfName=Build-dev, teamcity.agent.dotnet.agent_url=http://localhost:9090/RPC2, teamcity.build.id=111, agent.ownPort=9090, agent.name=MacAgent, build.number=82, teamcity.runner.properties.file=/Users/surecase/Desktop/buildAgent/temp/buildTmp/teamcity.runner3909938768619827374.properties, teamcity.build.changedFiles.file=/Users/surecase/Desktop/buildAgent/temp/buildTmp/changedFiles8064633368222257261.txt, teamcity.agent.cpuBenchmark=552, teamcity.build.workingDir=/Users/surecase/Desktop/buildAgent/work/88410410f80bbc04/Mobile/Android, agent.home.dir=/Users/surecase/Desktop/buildAgent, teamcity.auth.userId=TeamCityBuildId=111, teamcity.build.checkoutDir=/Users/surecase/Desktop/buildAgent/work/88410410f80bbc04, teamcity.configuration.properties.file=/Users/surecase/Desktop/buildAgent/temp/buildTmp/teamcity.config8874044708331653991.properties, build.vcs.number=a23e58c8ff92, teamcity.tests.recentlyFailedTests.file=/Users/surecase/Desktop/buildAgent/temp/buildTmp/testsToRunFirst6286498944890258669.txt, teamcity.projectName=Taxi5Mobile, agent.work.dir=/Users/surecase/Desktop/buildAgent/work, teamcity.build.tempDir=/Users/surecase/Desktop/buildAgent/temp/buildTmp, build.vcs.number.1=a23e58c8ff92, teamcity.auth.password=8dYVHDftOmXenz9cJjnCyctBrF5NKq7G, java.io.tmpdir=/Users/surecase/Desktop/buildAgent/temp/buildTmp, teamcity.build.properties.file=/Users/surecase/Desktop/buildAgent/temp/buildTmp/teamcity.build174113942945941853.properties, teamcity.agent.dotnet.build_id=111}

有些文件包含属性,但我不知道如何访问它们。

有任何想法吗?

最佳答案

可以使用标准Java API读取环境变量:

def dir = System.getenv("DIR")

使用比 DIR少一点歧义的名称可能是有道理的。

关于gradle - TeamCity-如何在Gradle中访问环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23296860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com