How to schedule the release trigger for every 15 days in Azure devops release pipeline

42 Views Asked by At

enter image description here

I'm not getting the logic for scheduling the trigger to release pipeline to run after every 15 days. Could anyone help..!

1

There are 1 best solutions below

0
Kevin Lu-MSFT On BEST ANSWER

I am afraid that there is no out-of-box method in Azure DevOps Release Pipeline can set the schedule trigger to run the Release Pipeline every 15 days.

In Azure DevOps Release Pipeline, the schedule trigger only supports setting days of the week and the specific time of trigger every day.

For a workaround, you can use the Schedule Trigger Cron in YAML Pipeline.

You can determine the running date of each month according to the actual situation and then add multiple Cron definitions.

For example:

schedules:
- cron: '0 8 26 March *'
  displayName: Daily midnight build
  branches:
    include:
    - main
- cron: '0 8 10,25 April *'
  displayName: Daily midnight build
  branches:
    include:
    - main

Then you can use the script to run Rest API: Releases - Create to trigger release or use extension task: Release Orchestrator extension to trigger the release in the YAML Pipeline.

For example:

Script:

schedules:
- cron: '0 8 26 March *'
  displayName: Daily midnight build
  branches:
    include:
    - main
- cron: '0 8 10,25 April *'
  displayName: Daily midnight build
  branches:
    include:
    - main
....

pool:
  vmImage: windows-latest

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $VSTSAccoutName="organiztionname"   
      $teamProjectName="projectname"
      $personaltoken = " PAT "
      $ReleaseMetadata = '{"definitionId":  15  }';
       
      $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personaltoken)"))
      $header = @{authorization = "Basic $token"}
      $Uri = 'https://vsrm.dev.azure.com/' + $VSTSAccoutName +'/'+ $teamProjectName + '/_apis/release/releases?api-version=5.0'
      $ReleaseResponse = Invoke-RestMethod -Method Post -ContentType application/json -Uri $Uri -Body $ReleaseMetadata -Headers $header
      Write-Host $ReleaseResponse

The Build Pipeline will run periodically as defined in cron, and then it will trigger the Release Pipeline so that it can run on the same date.

I can fully understand your requirement. You can submit a suggest ticket in the site: Developer Community to report this feature.