Skip to content

Commit

Permalink
Enable cron triggers defined in .teamcity to use branches that aren…
Browse files Browse the repository at this point in the history
  • Loading branch information
BBBmau authored and cmfeng committed Apr 5, 2024
1 parent 40e081b commit be6bfe9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package builds

import DefaultBranchName
import DefaultDaysOfMonth
import DefaultDaysOfWeek
import DefaultStartHour
Expand All @@ -15,18 +16,18 @@ import jetbrains.buildServer.configs.kotlin.Triggers
import jetbrains.buildServer.configs.kotlin.triggers.schedule

class NightlyTriggerConfiguration(
val branch: String = DefaultBranchName,
val nightlyTestsEnabled: Boolean = true,
val startHour: Int = DefaultStartHour,
val daysOfWeek: String = DefaultDaysOfWeek,
val daysOfMonth: String = DefaultDaysOfMonth
)

fun Triggers.runNightly(config: NightlyTriggerConfiguration) {
val filter = "+:refs/heads/main"

schedule{
enabled = config.nightlyTestsEnabled
branchFilter = filter
branchFilter = "+:" + config.branch // returns "+:/refs/heads/main" if default
triggerBuild = always() // Run build even if no new commits/pending changes
withPendingChangesOnly = false
enforceCleanCheckout = true
Expand Down
3 changes: 3 additions & 0 deletions mmv1/third_party/terraform/.teamcity/components/constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const val DefaultDaysOfWeek = "*"
// Cron value for any day of month
const val DefaultDaysOfMonth = "*"

// This represents the default branch to be used for testing
const val DefaultBranchName = "refs/heads/main"

// Value used to make long-running builds fail due to a timeout
const val DefaultBuildTimeoutDuration = 60 * 12 // 12 hours in minutes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package tests
import org.junit.Assert.assertTrue
import org.junit.Test
import jetbrains.buildServer.configs.kotlin.Project
import jetbrains.buildServer.configs.kotlin.triggers.ScheduleTrigger
import org.junit.Assert
import projects.googleCloudRootProject

Expand All @@ -29,13 +30,22 @@ class NightlyTestProjectsTests {
assertTrue("Build configuration `${bt.name}` contains at least one trigger", bt.triggers.items.isNotEmpty())
// Look for at least one CRON trigger
var found: Boolean = false
lateinit var schedulingTrigger: ScheduleTrigger
for (item in bt.triggers.items){
if (item.type == "schedulingTrigger") {
schedulingTrigger = item as ScheduleTrigger
found = true
break
}
}
assertTrue("Build configuration `${bt.name}` contains a CRON trigger", found)

// Check that nightly test is being ran on main branch
var isDefault: Boolean = false
if (schedulingTrigger.branchFilter == "+:refs/heads/main"){
isDefault = true
}
assertTrue("Build configuration `${bt.name} is using the default branch;", isDefault)
}
}
}

0 comments on commit be6bfe9

Please sign in to comment.