Skip to content

Commit 0402810

Browse files
committed
Teamcity build settings
1 parent 060bd3c commit 0402810

File tree

2 files changed

+345
-0
lines changed

2 files changed

+345
-0
lines changed

.teamcity/pom.xml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
<name>TeamCity Config DSL Script</name>
5+
<groupId>kotlinx.team.infra</groupId>
6+
<artifactId>teamcity</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<parent>
10+
<groupId>org.jetbrains.teamcity</groupId>
11+
<artifactId>configs-dsl-kotlin-parent</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
</parent>
14+
15+
<repositories>
16+
<repository>
17+
<id>jetbrains-all</id>
18+
<url>https://download.jetbrains.com/teamcity-repository</url>
19+
<snapshots>
20+
<enabled>true</enabled>
21+
</snapshots>
22+
</repository>
23+
<repository>
24+
<id>teamcity-server</id>
25+
<url>https://teamcity.jetbrains.com/app/dsl-plugins-repository</url>
26+
<snapshots>
27+
<enabled>true</enabled>
28+
</snapshots>
29+
</repository>
30+
</repositories>
31+
32+
<pluginRepositories>
33+
<pluginRepository>
34+
<id>JetBrains</id>
35+
<url>https://download.jetbrains.com/teamcity-repository</url>
36+
</pluginRepository>
37+
</pluginRepositories>
38+
39+
<build>
40+
<sourceDirectory>.</sourceDirectory>
41+
<plugins>
42+
<plugin>
43+
<artifactId>kotlin-maven-plugin</artifactId>
44+
<groupId>org.jetbrains.kotlin</groupId>
45+
<version>${kotlin.version}</version>
46+
47+
<configuration/>
48+
<executions>
49+
<execution>
50+
<id>compile</id>
51+
<phase>process-sources</phase>
52+
<goals>
53+
<goal>compile</goal>
54+
</goals>
55+
</execution>
56+
<execution>
57+
<id>test-compile</id>
58+
<phase>process-test-sources</phase>
59+
<goals>
60+
<goal>test-compile</goal>
61+
</goals>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
<plugin>
66+
<groupId>org.jetbrains.teamcity</groupId>
67+
<artifactId>teamcity-configs-maven-plugin</artifactId>
68+
<version>${teamcity.dsl.version}</version>
69+
<configuration>
70+
<format>kotlin</format>
71+
<dstDir>target/generated-configs</dstDir>
72+
</configuration>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
77+
<dependencies>
78+
<dependency>
79+
<groupId>org.jetbrains.teamcity</groupId>
80+
<artifactId>configs-dsl-kotlin</artifactId>
81+
<version>${teamcity.dsl.version}</version>
82+
<scope>compile</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.jetbrains.teamcity</groupId>
86+
<artifactId>configs-dsl-kotlin-plugins</artifactId>
87+
<version>1.0-SNAPSHOT</version>
88+
<type>pom</type>
89+
<scope>compile</scope>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.jetbrains.kotlin</groupId>
93+
<artifactId>kotlin-stdlib-jdk8</artifactId>
94+
<version>${kotlin.version}</version>
95+
<scope>compile</scope>
96+
</dependency>
97+
<dependency>
98+
<groupId>org.jetbrains.kotlin</groupId>
99+
<artifactId>kotlin-script-runtime</artifactId>
100+
<version>${kotlin.version}</version>
101+
<scope>compile</scope>
102+
</dependency>
103+
</dependencies>
104+
</project>

.teamcity/settings.kts

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
import jetbrains.buildServer.configs.kotlin.v2018_2.*
2+
import jetbrains.buildServer.configs.kotlin.v2018_2.buildSteps.*
3+
import jetbrains.buildServer.configs.kotlin.v2018_2.triggers.*
4+
5+
/*
6+
The settings script is an entry point for defining a TeamCity
7+
project hierarchy. The script should contain a single call to the
8+
project() function with a Project instance or an init function as
9+
an argument.
10+
11+
VcsRoots, BuildTypes, Templates, and subprojects can be
12+
registered inside the project using the vcsRoot(), buildType(),
13+
template(), and subProject() methods respectively.
14+
15+
To debug settings scripts in command-line, run the
16+
17+
mvnDebug org.jetbrains.teamcity:teamcity-configs-maven-plugin:generate
18+
19+
command and attach your debugger to the port 8000.
20+
21+
To debug in IntelliJ Idea, open the 'Maven Projects' tool window (View
22+
-> Tool Windows -> Maven Projects), find the generate task node
23+
(Plugins -> teamcity-configs -> teamcity-configs:generate), the
24+
'Debug' option is available in the context menu for the task.
25+
*/
26+
27+
version = "2018.2"
28+
val versionSuffixParameter = "versionSuffix"
29+
val teamcitySuffixParameter = "teamcitySuffix"
30+
val releaseVersionParameter = "releaseVersion"
31+
32+
val bintrayUserName = "bintrayUser"
33+
val bintrayToken = "bintrayToken"
34+
35+
val platforms = listOf("Windows", "Linux", "Mac OS X")
36+
val jdk = "JDK_18_x64"
37+
38+
project {
39+
// Disable editing of project and build settings from the UI to avoid issues with TeamCity
40+
params {
41+
param("teamcity.ui.settings.readOnly", "true")
42+
}
43+
44+
val buildAll = buildAll()
45+
val builds = platforms.map { build(it) }
46+
builds.forEach { build ->
47+
buildAll.dependsOn(build) {
48+
snapshot {
49+
onDependencyFailure = FailureAction.ADD_PROBLEM
50+
onDependencyCancel = FailureAction.CANCEL
51+
}
52+
}
53+
buildAll.dependsOn(build) {
54+
artifacts {
55+
artifactRules = "+:maven=>maven\n+:api=>api"
56+
}
57+
}
58+
}
59+
60+
val deployConfigure = deployConfigure()
61+
val deploys = platforms.map { deploy(it, deployConfigure) }
62+
val deployPublish = deployPublish(deployConfigure).apply {
63+
deploys.forEach {
64+
dependsOnSnapshot(it)
65+
}
66+
}
67+
68+
buildTypesOrder = listOf(buildAll) + builds + deployPublish + deployConfigure + deploys
69+
}
70+
71+
fun Project.buildAll() = BuildType {
72+
id("Build_All")
73+
this.name = "Build (All)"
74+
type = BuildTypeSettings.Type.COMPOSITE
75+
76+
triggers {
77+
vcs {
78+
triggerRules = """
79+
-:*.md
80+
-:.gitignore
81+
""".trimIndent()
82+
}
83+
}
84+
85+
commonConfigure()
86+
}.also { buildType(it) }
87+
88+
fun Project.build(platform: String) = platform(platform, "Build") {
89+
steps {
90+
gradle {
91+
name = "Build and Test $platform Binaries"
92+
jdkHome = "%env.$jdk%"
93+
jvmArgs = "-Xmx1g"
94+
tasks = "clean publishToBuildLocal check"
95+
// --continue is needed to run tests for all targets even if one target fails
96+
gradleParams = "--info --stacktrace -P$versionSuffixParameter=SNAPSHOT -P$teamcitySuffixParameter=%build.counter% --continue"
97+
buildFile = ""
98+
gradleWrapperPath = ""
99+
}
100+
}
101+
102+
// What files to publish as build artifacts
103+
artifactRules = "+:build/maven=>maven\n+:build/api=>api"
104+
}
105+
106+
fun BuildType.dependsOn(build: BuildType, configure: Dependency.() -> Unit) =
107+
apply {
108+
dependencies.dependency(build, configure)
109+
}
110+
111+
fun BuildType.dependsOnSnapshot(build: BuildType, configure: SnapshotDependency.() -> Unit = {}) = apply {
112+
dependencies.dependency(build) {
113+
snapshot {
114+
configure()
115+
onDependencyFailure = FailureAction.FAIL_TO_START
116+
onDependencyCancel = FailureAction.CANCEL
117+
}
118+
}
119+
}
120+
121+
fun Project.deployConfigure() = BuildType {
122+
id("Deploy_Configure")
123+
this.name = "Deploy (Configure)"
124+
commonConfigure()
125+
126+
params {
127+
// enable editing of this configuration to set up things
128+
param("teamcity.ui.settings.readOnly", "false")
129+
param("bintray-user", bintrayUserName)
130+
password("bintray-key", bintrayToken)
131+
param(versionSuffixParameter, "dev-%build.counter%")
132+
}
133+
134+
requirements {
135+
// Require Linux for configuration build
136+
contains("teamcity.agent.jvm.os.name", "Linux")
137+
}
138+
139+
steps {
140+
gradle {
141+
name = "Verify Gradle Configuration"
142+
tasks = "clean publishBintrayCreateVersion"
143+
gradleParams = "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$releaseVersionParameter=%$releaseVersionParameter% -PbintrayApiKey=%bintray-key% -PbintrayUser=%bintray-user%"
144+
buildFile = ""
145+
jdkHome = "%env.$jdk%"
146+
}
147+
}
148+
}.also { buildType(it) }
149+
150+
fun Project.deployPublish(configureBuild: BuildType) = BuildType {
151+
id("Deploy_Publish")
152+
this.name = "Deploy (Publish)"
153+
type = BuildTypeSettings.Type.COMPOSITE
154+
params {
155+
param(versionSuffixParameter, "${configureBuild.depParamRefs[versionSuffixParameter]}")
156+
157+
// Tell configuration build how to get release version parameter from this build
158+
// "dev" is the default and means publishing is not releasing to public
159+
param(configureBuild.reverseDepParamRefs[releaseVersionParameter].name, "dev")
160+
}
161+
commonConfigure()
162+
}.also { buildType(it) }.dependsOnSnapshot(configureBuild)
163+
164+
165+
fun Project.deploy(platform: String, configureBuild: BuildType) = platform(platform, "Deploy") {
166+
type = BuildTypeSettings.Type.DEPLOYMENT
167+
enablePersonalBuilds = false
168+
maxRunningBuilds = 1
169+
params {
170+
param(versionSuffixParameter, "${configureBuild.depParamRefs[versionSuffixParameter]}")
171+
param(releaseVersionParameter, "${configureBuild.depParamRefs[releaseVersionParameter]}")
172+
param("bintray-user", bintrayUserName)
173+
password("bintray-key", bintrayToken)
174+
}
175+
176+
vcs {
177+
cleanCheckout = true
178+
}
179+
180+
steps {
181+
gradle {
182+
name = "Deploy $platform Binaries"
183+
jdkHome = "%env.$jdk%"
184+
jvmArgs = "-Xmx1g"
185+
gradleParams = "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$releaseVersionParameter=%$releaseVersionParameter% -PbintrayApiKey=%bintray-key% -PbintrayUser=%bintray-user%"
186+
tasks = "clean build publish"
187+
buildFile = ""
188+
gradleWrapperPath = ""
189+
}
190+
}
191+
}.dependsOnSnapshot(configureBuild)
192+
193+
fun Project.platform(platform: String, name: String, configure: BuildType.() -> Unit) = BuildType {
194+
// ID is prepended with Project ID, so don't repeat it here
195+
// ID should conform to identifier rules, so just letters, numbers and underscore
196+
id("${name}_${platform.substringBefore(" ")}")
197+
// Display name of the build configuration
198+
this.name = "$name ($platform)"
199+
200+
requirements {
201+
contains("teamcity.agent.jvm.os.name", platform)
202+
}
203+
204+
params {
205+
// This parameter is needed for macOS agent to be compatible
206+
param("env.JDK_17", "")
207+
}
208+
209+
commonConfigure()
210+
configure()
211+
}.also { buildType(it) }
212+
213+
214+
fun BuildType.commonConfigure() {
215+
requirements {
216+
noLessThan("teamcity.agent.hardware.memorySizeMb", "6144")
217+
}
218+
219+
// Allow to fetch build status through API for badges
220+
allowExternalStatus = true
221+
222+
// Configure VCS, by default use the same and only VCS root from which this configuration is fetched
223+
vcs {
224+
root(DslContext.settingsRoot)
225+
showDependenciesChanges = true
226+
checkoutMode = CheckoutMode.ON_AGENT
227+
}
228+
229+
failureConditions {
230+
errorMessage = true
231+
nonZeroExitCode = true
232+
executionTimeoutMin = 120
233+
}
234+
235+
features {
236+
feature {
237+
id = "perfmon"
238+
type = "perfmon"
239+
}
240+
}
241+
}

0 commit comments

Comments
 (0)