|
| 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 = "%env.BINTRAY_USER%" |
| 33 | +val bintrayToken = "%env.BINTRAY_API_KEY%" |
| 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 buildVersion = buildVersion() |
| 45 | + val buildAll = buildAll(buildVersion) |
| 46 | + val builds = platforms.map { build(it, buildVersion) } |
| 47 | + builds.forEach { build -> |
| 48 | + buildAll.dependsOnSnapshot(build, onFailure = FailureAction.ADD_PROBLEM) |
| 49 | + buildAll.dependsOn(build) { |
| 50 | + artifacts { |
| 51 | + artifactRules = "+:maven=>maven\n+:api=>api" |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + val deployConfigure = deployConfigure().apply { |
| 57 | + dependsOnSnapshot(buildAll, onFailure = FailureAction.IGNORE) |
| 58 | + } |
| 59 | + val deploys = platforms.map { deploy(it, deployConfigure) } |
| 60 | + val deployPublish = deployPublish(deployConfigure).apply { |
| 61 | + dependsOnSnapshot(buildAll, onFailure = FailureAction.IGNORE) |
| 62 | + deploys.forEach { |
| 63 | + dependsOnSnapshot(it) |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + buildTypesOrder = listOf(buildAll, buildVersion, *builds.toTypedArray(), deployPublish, deployConfigure, *deploys.toTypedArray()) |
| 68 | +} |
| 69 | + |
| 70 | +fun Project.buildVersion() = BuildType { |
| 71 | + id("Build_Version") |
| 72 | + this.name = "Build (Configure Version)" |
| 73 | + commonConfigure() |
| 74 | + |
| 75 | + params { |
| 76 | + param(versionSuffixParameter, "SNAPSHOT") |
| 77 | + param(teamcitySuffixParameter, "%build.counter%") |
| 78 | + } |
| 79 | + |
| 80 | + steps { |
| 81 | + gradle { |
| 82 | + name = "Generate build chain version" |
| 83 | + jdkHome = "%env.$jdk%" |
| 84 | + tasks = "" |
| 85 | + gradleParams = "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$teamcitySuffixParameter=%$teamcitySuffixParameter%" |
| 86 | + buildFile = "" |
| 87 | + gradleWrapperPath = "" |
| 88 | + } |
| 89 | + } |
| 90 | +}.also { buildType(it) } |
| 91 | + |
| 92 | +fun Project.buildAll(versionBuild: BuildType) = BuildType { |
| 93 | + id("Build_All") |
| 94 | + this.name = "Build (All)" |
| 95 | + type = BuildTypeSettings.Type.COMPOSITE |
| 96 | + |
| 97 | + dependsOnSnapshot(versionBuild) |
| 98 | + buildNumberPattern = versionBuild.depParamRefs.buildNumber.ref |
| 99 | + |
| 100 | + triggers { |
| 101 | + vcs { |
| 102 | + triggerRules = """ |
| 103 | + -:*.md |
| 104 | + -:.gitignore |
| 105 | + """.trimIndent() |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + commonConfigure() |
| 110 | +}.also { buildType(it) } |
| 111 | + |
| 112 | +fun Project.build(platform: String, versionBuild: BuildType) = platform(platform, "Build") { |
| 113 | + |
| 114 | + dependsOnSnapshot(versionBuild) |
| 115 | + |
| 116 | + params { |
| 117 | + param(versionSuffixParameter, versionBuild.depParamRefs[versionSuffixParameter].ref) |
| 118 | + param(teamcitySuffixParameter, versionBuild.depParamRefs[teamcitySuffixParameter].ref) |
| 119 | + } |
| 120 | + |
| 121 | + steps { |
| 122 | + gradle { |
| 123 | + name = "Build and Test $platform Binaries" |
| 124 | + jdkHome = "%env.$jdk%" |
| 125 | + jvmArgs = "-Xmx1g" |
| 126 | + tasks = "clean publishToBuildLocal check" |
| 127 | + // --continue is needed to run tests for all targets even if one target fails |
| 128 | + gradleParams = "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$teamcitySuffixParameter=%$teamcitySuffixParameter% --continue" |
| 129 | + buildFile = "" |
| 130 | + gradleWrapperPath = "" |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + // What files to publish as build artifacts |
| 135 | + artifactRules = "+:build/maven=>maven\n+:build/api=>api" |
| 136 | +} |
| 137 | + |
| 138 | +fun BuildType.dependsOn(build: BuildType, configure: Dependency.() -> Unit) = |
| 139 | + apply { |
| 140 | + dependencies.dependency(build, configure) |
| 141 | + } |
| 142 | + |
| 143 | +fun BuildType.dependsOnSnapshot(build: BuildType, onFailure: FailureAction = FailureAction.FAIL_TO_START, configure: SnapshotDependency.() -> Unit = {}) = apply { |
| 144 | + dependencies.dependency(build) { |
| 145 | + snapshot { |
| 146 | + configure() |
| 147 | + onDependencyFailure = onFailure |
| 148 | + onDependencyCancel = FailureAction.CANCEL |
| 149 | + } |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +fun Project.deployConfigure() = BuildType { |
| 154 | + id("Deploy_Configure") |
| 155 | + this.name = "Deploy (Configure Version)" |
| 156 | + commonConfigure() |
| 157 | + |
| 158 | + params { |
| 159 | + // enable editing of this configuration to set up things |
| 160 | + param("teamcity.ui.settings.readOnly", "false") |
| 161 | + param("bintray-user", bintrayUserName) |
| 162 | + password("bintray-key", bintrayToken) |
| 163 | + param(versionSuffixParameter, "dev-%build.counter%") |
| 164 | + } |
| 165 | + |
| 166 | + requirements { |
| 167 | + // Require Linux for configuration build |
| 168 | + contains("teamcity.agent.jvm.os.name", "Linux") |
| 169 | + } |
| 170 | + |
| 171 | + steps { |
| 172 | + gradle { |
| 173 | + name = "Verify Gradle Configuration" |
| 174 | + tasks = "clean publishBintrayCreateVersion" |
| 175 | + gradleParams = "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$releaseVersionParameter=%$releaseVersionParameter% -PbintrayApiKey=%bintray-key% -PbintrayUser=%bintray-user%" |
| 176 | + buildFile = "" |
| 177 | + jdkHome = "%env.$jdk%" |
| 178 | + } |
| 179 | + } |
| 180 | +}.also { buildType(it) } |
| 181 | + |
| 182 | +fun Project.deployPublish(configureBuild: BuildType) = BuildType { |
| 183 | + id("Deploy_Publish") |
| 184 | + this.name = "Deploy (Publish)" |
| 185 | + type = BuildTypeSettings.Type.COMPOSITE |
| 186 | + dependsOnSnapshot(configureBuild) |
| 187 | + buildNumberPattern = configureBuild.depParamRefs.buildNumber.ref |
| 188 | + params { |
| 189 | + // Tell configuration build how to get release version parameter from this build |
| 190 | + // "dev" is the default and means publishing is not releasing to public |
| 191 | + text(configureBuild.reverseDepParamRefs[releaseVersionParameter].name, "dev", display = ParameterDisplay.PROMPT, label = "Release Version") |
| 192 | + } |
| 193 | + commonConfigure() |
| 194 | +}.also { buildType(it) } |
| 195 | + |
| 196 | + |
| 197 | +fun Project.deploy(platform: String, configureBuild: BuildType) = platform(platform, "Deploy") { |
| 198 | + type = BuildTypeSettings.Type.DEPLOYMENT |
| 199 | + enablePersonalBuilds = false |
| 200 | + maxRunningBuilds = 1 |
| 201 | + params { |
| 202 | + param(versionSuffixParameter, "${configureBuild.depParamRefs[versionSuffixParameter]}") |
| 203 | + param(releaseVersionParameter, "${configureBuild.depParamRefs[releaseVersionParameter]}") |
| 204 | + param("bintray-user", bintrayUserName) |
| 205 | + password("bintray-key", bintrayToken) |
| 206 | + } |
| 207 | + |
| 208 | + vcs { |
| 209 | + cleanCheckout = true |
| 210 | + } |
| 211 | + |
| 212 | + steps { |
| 213 | + gradle { |
| 214 | + name = "Deploy $platform Binaries" |
| 215 | + jdkHome = "%env.$jdk%" |
| 216 | + jvmArgs = "-Xmx1g" |
| 217 | + gradleParams = "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$releaseVersionParameter=%$releaseVersionParameter% -PbintrayApiKey=%bintray-key% -PbintrayUser=%bintray-user%" |
| 218 | + tasks = "clean publish" |
| 219 | + buildFile = "" |
| 220 | + gradleWrapperPath = "" |
| 221 | + } |
| 222 | + } |
| 223 | +}.dependsOnSnapshot(configureBuild) |
| 224 | + |
| 225 | +fun Project.platform(platform: String, name: String, configure: BuildType.() -> Unit) = BuildType { |
| 226 | + // ID is prepended with Project ID, so don't repeat it here |
| 227 | + // ID should conform to identifier rules, so just letters, numbers and underscore |
| 228 | + id("${name}_${platform.substringBefore(" ")}") |
| 229 | + // Display name of the build configuration |
| 230 | + this.name = "$name ($platform)" |
| 231 | + |
| 232 | + requirements { |
| 233 | + contains("teamcity.agent.jvm.os.name", platform) |
| 234 | + } |
| 235 | + |
| 236 | + params { |
| 237 | + // This parameter is needed for macOS agent to be compatible |
| 238 | + if (platform.startsWith("Mac")) param("env.JDK_17", "") |
| 239 | + } |
| 240 | + |
| 241 | + commonConfigure() |
| 242 | + configure() |
| 243 | +}.also { buildType(it) } |
| 244 | + |
| 245 | + |
| 246 | +fun BuildType.commonConfigure() { |
| 247 | + requirements { |
| 248 | + noLessThan("teamcity.agent.hardware.memorySizeMb", "6144") |
| 249 | + } |
| 250 | + |
| 251 | + // Allow to fetch build status through API for badges |
| 252 | + allowExternalStatus = true |
| 253 | + |
| 254 | + // Configure VCS, by default use the same and only VCS root from which this configuration is fetched |
| 255 | + vcs { |
| 256 | + root(DslContext.settingsRoot) |
| 257 | + showDependenciesChanges = true |
| 258 | + checkoutMode = CheckoutMode.ON_AGENT |
| 259 | + } |
| 260 | + |
| 261 | + failureConditions { |
| 262 | + errorMessage = true |
| 263 | + nonZeroExitCode = true |
| 264 | + executionTimeoutMin = 120 |
| 265 | + } |
| 266 | + |
| 267 | + features { |
| 268 | + feature { |
| 269 | + id = "perfmon" |
| 270 | + type = "perfmon" |
| 271 | + } |
| 272 | + } |
| 273 | +} |
0 commit comments