Skip to content

Only run pipeline from non-main branches#240

Open
sroghanchi wants to merge 1 commit intomainfrom
personal/sroghanchi/preventpipelinefrommain
Open

Only run pipeline from non-main branches#240
sroghanchi wants to merge 1 commit intomainfrom
personal/sroghanchi/preventpipelinefrommain

Conversation

@sroghanchi
Copy link
Collaborator

No description provided.

stages:
- stage: BuildPackages
displayName: "Build and Package Artifacts"
condition: ne(variables['Build.SourceBranch'], 'refs/heads/main')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It restricts running from main, but what if someone wants to test changes from main itself?
we should add some conditions like-
1> if main/non-main, then make sure release number should be less than 3.0.0
2> allow release/* branch for all versions

Let me know your thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did something similar check in release.yaml for github pipeline too, can refer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I was thinking that test changes can be run from the test branches and not main, but you are right we should also restrict the release version from non-release branches.

@sroghanchi sroghanchi force-pushed the personal/sroghanchi/preventpipelinefrommain branch 4 times, most recently from df13dfb to 9163c67 Compare June 26, 2025 15:35
exit 1
fi
fi
displayName: 'Validate versionName for non-release branches'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use of this?

# ADO pipelines documentation:
# https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml
stages:
- stage: CheckVersion
Copy link
Collaborator

@palashvij-msft palashvij-msft Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands

- job: CheckVersion
  steps:
  - script: |
 
      echo "##[section]Version validation script started"
      echo "Branch ref: $(Build.SourceBranch)"
      echo "Provided version: ${{ parameters.versionName }}"

      # Extract the actual branch name from the full reference (e.g., refs/heads/feature/foo -> feature/foo)
      branchName="$(echo "$(Build.SourceBranch)" | sed 's#refs/heads/##')"
      echo "Extracted branch name: $branchName"

      # Define the release branch and minimum allowed version for flexibility
      release_branch="release/3.0"
      min_version="3.0.0"

      # Only validate version if NOT on the release branch
      if [[ "$branchName" != "$release_branch" ]]; then
        version="${{ parameters.versionName }}"
        echo "##[command]Non-release branch detected. Checking if version $version exceeds allowed minimum ($min_version)..."

        # Compare version using natural version sort
        if [[ "$(echo -e "$version\n$min_version" | sort -V | head -n1)" != "$version" ]]; then
          echo "##[error]Version $version is NOT permitted on non-release branches (must be <= $min_version)."
          exit 1
        else
          echo "##[command]Version check PASSED: $version is allowed on $branchName."
        fi
      else
        echo "##[command]On release branch ($release_branch). Version check skipped."
      fi

      echo "##[section]Version validation script completed"
    displayName: 'Validate versionName for non-release branches'

@sroghanchi sroghanchi force-pushed the personal/sroghanchi/preventpipelinefrommain branch from 9163c67 to 4723e37 Compare July 8, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants