microsoft / terraform-provider-azuredevops

Terraform Azure DevOps provider
https://www.terraform.io/docs/providers/azuredevops/
MIT License
387 stars 280 forks source link

Build definition - Schedule set fine but never starts #671

Open garddolau opened 1 year ago

garddolau commented 1 year ago

Community Note

Terraform (and Azure DevOps Provider) Version

Affected Resource(s)

Terraform Configuration Files

resource "azuredevops_build_definition" "my_pipeline" {
  project_id = data.azuredevops_project.my_project.id
  path       = "\\my_path"
  name       = "my_pipeline"

  ci_trigger {
    use_yaml = false
  }

  repository {
    repo_type   = "TfsGit"
    repo_id     = azuredevops_git_repository.my_repo.id
    branch_name = "refs/heads/main"
    yml_path    = "pipelines/scheduled/my_yaml.pipeline.yml"
  }

  schedules {
    branch_filter {
      exclude = []
      include = ["refs/heads/main"]
    }

    days_to_build = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] 
    schedule_only_with_changes = false
    start_hours                 = 12
    start_minutes             = 30
    time_zone                  = "(UTC+00:00) Dublin, Edinburgh, Lisbon, London"
  }
}

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform apply

Important Factoids

References

xuzhang3 commented 1 year ago

@garddolau you should set use_yaml=false otherwise the the pipeline trigger will use the triggers defined in the YML.

ci_trigger {
    use_yaml = true
  }
garddolau commented 1 year ago

Hi @xuzhang3, just tried with use_yaml = false. I can that reflect in the portal. Unfortunately it still never triggered on the set schedule. Regards Darren

xuzhang3 commented 1 year ago

@garddolau my pipeline triggered as scheduled. Is there any error logs or can run the pipeline manually?

image
mariussm commented 1 year ago

We have the same issue. Investigating whether there is a behind the scenes attribute somewhere. Very annoying as we create 100s of pipelines using TF.

olofmattsson-inriver commented 10 months ago

Hi,

I've run into this problem as well, but in my case, some scheduled pipelines work and some don't. I think the reason some work is: The pipeline definition was created with a ci_trigger { overrides = { batch = true}} and then they were updated to ci_trigger { use_yaml = false } are scheduled and run correctly. The pipelines that are created directly using ci_trigger { use_yaml = false } have a schedule but are not run.

Looking at https://learn.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml#batch-considerations-for-scheduled-triggers I think that the option to always run needs to be added to the provider to fix this.

According to the yaml https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/schedules-cron?view=azure-pipelines the always = true needs to be set.

I will continue to investigate the Azure Devops API response to see if I can verify this.

olofmattsson-inriver commented 10 months ago

Hi,

I have spent a couple of hours with Azure DevOps support and testing this behaviour. I can confirm that when you create a scheduled run using Terraform it is created but never run. If I update the existing schedule and move the run time 10 minutes forward, it works. The same behaviour exists if I update the schedule using Terraform or the Azure DevOps web interface.

I'm not a Go developer but it looks like there is a difference in how the API is called when creating or updating an existing build definition.

xuzhang3 commented 2 weeks ago

Add skip_first_run=false to ensure the pipe will be triggered after created

 features {
    skip_first_run = false
  }

More details: https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs/resources/build_definition#skip_first_run-1