Forum Discussion

Dashers's avatar
Dashers
Copper Contributor
Oct 07, 2024

Azure DevOps git tag release pipeline

I'm wanting to get an Azure DevOps Pipeline (Classic) to run on a schedule against a Git Tag.  This tag is set by a CD pipeline to mark when it has been deployed in the live environment.  The scenario is that a "safe" release can be re-released on a regular schedule to ensure that it still matches what is expected (it's an Azure ARM release, and I want to tidy up any unauthorised changes made by lazy engineers).

 

I cannot though find a way to achieve this.  While you can filter on tags from builds in a release pipeline, that's not Git tags, but things manually set in ADO.  I have tried using a build pipeline first (don't actually need one for this, but I can live with it) and using a branch filter to refs/tags/mytag, but it never seems to run.

 

Can anybody help out here?

  • Dashers 

     

    Try this, please make sure you are fully understand the script before apply:

     

    $tag = "mytag"
    $tags = git tag --list
    if ($tags -contains $tag) {
    Write-Host "Tag $tag found. Proceeding with the build."
    # Add your build steps here
    } else {
    Write-Host "Tag $tag not found. Skipping the build."
    exit 0
    }

  • Dashers 

     

    Please try these steps.

    1. Create a Build Pipeline:
    Set up a build pipeline that runs on a schedule (daily, weekly, etc.).
    In this pipeline, add a script to check if the specific Git tag exists.

     

    2. Script to Check for the Git Tag:
    Use a script task like this (for example, in Bash):
    git fetch --tags
    if git rev-parse "refs/tags/mytag" >/dev/null 2>&1; then
    echo "Tag found, proceed with release."
    exit 0
    else
    echo "Tag not found, stop pipeline."
    exit 1
    fi


    3. Trigger a Release Pipeline:
    In the release pipeline, use the output of the build pipeline (when the tag is found) as the trigger.
    This release pipeline will redeploy the ARM templates or perform cleanup tasks.

     

    4. Schedule the Pipeline:

    Configure the build pipeline to run on a schedule, ensuring it checks for the tag regularly.

     

    With this setup, the pipeline will only trigger the release if the specific Git tag is found during the scheduled run.

     

    Reference URL:

    1. Build GitHub repositories - Azure Pipelines | Microsoft Learn

    2. https://learn.microsoft.com/en-us/azure/devops/pipelines/build/build-tag?view=azure-devops&tabs=azure-pipelines-ui

     

Resources