Skip to content

Commit

Permalink
Merge pull request #452 from xuzhang3/f/build_definition_schedule
Browse files Browse the repository at this point in the history
Enhance Build Definition : Support schedules
  • Loading branch information
xuzhang3 authored Sep 29, 2021
2 parents a07e0d6 + 6c4813c commit b00f784
Show file tree
Hide file tree
Showing 6 changed files with 1,060 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ func TestAccBuildDefinition_WithVariables_CreateAndUpdate(t *testing.T) {
})
}

func TestAccBuildDefinition_Schedules(t *testing.T) {
name := testutils.GenerateResourceName()
tfNode := "azuredevops_build_definition.build"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: checkBuildDefinitionDestroyed,
Steps: []resource.TestStep{
{
Config: hclBuildDefinitionSchedules(name),
Check: resource.ComposeTestCheckFunc(
checkBuildDefinitionExists(name),
resource.TestCheckResourceAttrSet(tfNode, "project_id"),
resource.TestCheckResourceAttrSet(tfNode, "revision"),
resource.TestCheckResourceAttrSet(tfNode, "repository.0.repo_id"),
resource.TestCheckResourceAttr(tfNode, "schedules.#", "1"),
resource.TestCheckResourceAttr(tfNode, "schedules.0.days_to_build.#", "1"),
resource.TestCheckResourceAttr(tfNode, "name", name),
),
},
},
})
}

// Checks that the expected variable values exist in the state
func checkForVariableValues(tfNode string, expectedVals ...string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -240,3 +264,62 @@ func getBuildDefinitionFromResource(resource *terraform.ResourceState) (*build.B
DefinitionId: &buildDefID,
})
}

func hclBuildDefinitionSchedules(name string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "test" {
name = "%[1]s"
description = "%[1]s-description"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "test" {
project_id = azuredevops_project.test.id
name = "acc-%[1]s"
initialization {
init_type = "Clean"
}
}
resource "azuredevops_build_definition" "build" {
project_id = azuredevops_project.test.id
name = "%[1]s"
path = "\\ExampleFolder"
ci_trigger {
override {
batch = true
branch_filter {
include = ["master"]
}
path_filter {
include = ["*/**.ts"]
}
max_concurrent_builds_per_branch = 2
polling_interval = 0
}
}
schedules {
branch_filter {
include = ["master"]
}
days_to_build = ["Mon"]
schedule_only_with_changes = true
start_hours = 0
start_minutes = 0
time_zone = "(UTC) Coordinated Universal Time"
}
repository {
repo_type = "TfsGit"
repo_id = azuredevops_git_repository.test.id
branch_name = azuredevops_git_repository.test.default_branch
yml_path = "azure-pipelines.yml"
}
}
`, name)
}
Loading

0 comments on commit b00f784

Please sign in to comment.