skip to Main Content

I currently have an existing yml in a specific folder for CI build. Every time a PR (change) is checked in, we will trigger the CI build.

Now, how do I add or combine the yml for dependabot, considering that in the dependabot we have trigger set to none versus in the CI, we have trigger set to a specific branch ? Ideally, we only want to run the dependabot scan only one time a week. Is it achievable with the v2 dependabot ? Thank you.

azure-pipelines.yml

# ASP.NET Core

# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
---
variables:
  - name: buildConfiguration
    value: Release
  - name: agentPool
    "${{ if or(eq(variables['Build.SourceBranchName'], 'dev'), eq(variables['Build.SourceBranchName'], 'main'), eq(variables['Build.SourceBranchName'], 'dev-ttcdbtst')) }}":
      value: "TTC Servers"
    "${{ else }}":
      value: Azure Pipelines
  - name: rootPath
    value: "./../../../"
  - name: projectPath
    value: "./../"
  - name: unitTestPath
    value: "./../../Api.Test"
  - name: workingDirectory
    value: "src/Api/Build"
trigger:
  - main
  - dev  
  - feature/*
jobs:
  - job: null
    displayName: Build and Publish Artifacts
    pool:
      name: $(agentPool)
      vmImage: ubuntu-latest    
    steps:    
    - checkout: self
      fetchDepth: 0
    - task: UseDotNet@2
      displayName: 'Install .NET 8 SDK'
      inputs:
        packageType: 'sdk'
        version: '8.x'
    - task: Bash@3
      displayName: 'Check what account is running'
      inputs:
        targetType: 'inline'
        script: 'whoami'
        workingDirectory: $(workingDirectory)
    - task: Bash@3
      displayName: 'Install Cake.Tool'
      inputs:
        targetType: 'inline'
        script: 'dotnet tool install --global Cake.Tool | echo "Already installed"'
        workingDirectory: $(workingDirectory)
    - task: Bash@3
      displayName: 'Execute dotnet cake command'
      inputs:
        targetType: 'inline'
        script: 'dotnet cake --rootPath=$(rootPath) --projectPath=$(projectPath) --unitTestPath=$(unitTestPath)'
        workingDirectory: $(workingDirectory)
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Build Artifacts'
      inputs:
        PathtoPublish: 'artifacts'
        ArtifactName: 'Artifact'
        publishLocation: 'Container'

dependabot-pipelines.yml

#inputs options: https://github.com/tinglesoftware/dependabot-azure-devops/blob/main/extension/README.md
trigger: none
stages:
  - stage: CheckDependencies
    displayName: Check Dependencies
    jobs:
      - job: Dependabot
        displayName: Run Dependabot
        pool:
          vmImage: ubuntu-latest
        steps:
          - task: dependabot@2
            displayName: Run Dependabot            
            inputs:
              setAutoComplete: true

dependabot.yml

version: 2
updates:
  - package-ecosystem: 'nuget'
    directory: '/'
    target-branch: 'dev'
    open-pull-requests-limit: 15
    ignore:
        - dependency-name: 'Microsoft.Extensions.Caching.SqlServer'
    registries:
      - azure_artifacts
    schedule:
      interval: weekly
      # Check for npm updates on every Sundays
      day: "sunday"
      time: "09:00"
      timezone: "America/Los_Angeles"    
    # Labels on pull requests for security and version updates
    labels:
      - "npm dependencies"
registries:
  azure_artifacts:
    type: "nuget-feed"
    url: "https://xxx.pkgs.visualstudio.com/0497dd12-e7ca-49f7-999e-7f22d25e38c8/_packaging/TTCWebFeed/nuget/v3/index.json"
    token: "PAT:<PAT>"

2

Answers


  1. Chosen as BEST ANSWER

    Thanks @Alvin for pointing me to the right direction. However, the scheduler in his yml file is somehow not recognized by Azure, even though the file is validated with no issue. I had to modify it a bit, not sure what is wrong.

    Here is my modified yml:

    # ASP.NET Core
    
    # Build and test ASP.NET Core projects targeting .NET Core.
    # Add steps that run tests, create a NuGet package, deploy, and more:
    # https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
    #inputs options: https://github.com/tinglesoftware/dependabot-azure-devops/blob/main/extension/README.md
    trigger: none 
    schedules:
    - cron: 0 13 * * 0 # 1pm in UTC = 6/7am PST cron syntax defining a schedule
      displayName: weekly build on Sunday # friendly name given to a specific schedule
      branches:
        include: [ dev ] # which branches the schedule applies to
      always: true # whether to always run the pipeline at the scheduled time, even if there have been no changes
      batch: false # whether to run the pipeline if the previously scheduled run is in-progress; the default is false
    jobs:
      - job: null
        displayName: Scan dependencies
        pool:
          name: Azure Pipelines
          vmImage: ubuntu-latest    
        steps:    
        - task: dependabot@2
          displayName: 'Run Dependabot'
          inputs:
            autoApprove: true
            setAutoComplete: true
    

  2. You may create a new pipeline referencing the dependabot-pipelines.yml definition that uses the Scheduled triggers. Make sure the dependabot-pipelines.yml definition file exists in the expected branch.

    Here is a sample YAML pipeline with weekly trigger upon new source code changes in dev branch, since the last successful scheduled run.

    trigger: none
    
    schedules:
    - cron: 0 16 * * 0 # UTC
      displayName: Weekly Sunday Scan # friendly name given to a specific schedule
      branches:
        include:
        - dev # which branches the schedule applies to
      always: false # whether to always run the pipeline or only if there have been source code changes since the last successful scheduled run. The default is false.
      batch: false # Whether to run the pipeline if the previously scheduled run is in-progress; the default is false.
      # batch is available in Azure DevOps Server 2022.1 and higher
    
    stages:
    - stage: CheckDependencies
      displayName: Check Dependencies
      jobs:
        - job: Dependabot
          displayName: Run Dependabot
          pool:
            vmImage: ubuntu-latest
          steps:
          - task: dependabot@2
            displayName: Run Dependabot
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search