Azure-devops-docs: condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/release-v') will not work

Created on 21 Jul 2019  Â·  6Comments  Â·  Source: MicrosoftDocs/azure-devops-docs

This condition will not work since it checks a branch name against the tag name - those will not match. The condition is good for matching branch names only. I suggest to change description to reflect it works for branch name comparison not to confuse.

If there is a way to have a condition matched on tag name, it would be nice to add that somewhere to the documentation.

condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/release-v').


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 devops-cictech devopprod doc-bug

Most helpful comment

If your build is triggered by a tag when you have ie.:

trigger:
  branches:
    include:
    - refs/heads/development
    - refs/heads/master
    - refs/tags/release-v*
    exclude:

then the ['Build.SourceBranch'] will be the name of the tag, ie.: refs/tags/release-v1

So the condition will work. I'm using it this way to only trigger a certain stage for commits, which are tagged.

All 6 comments

Does anyone know of a way to achieve the above condition for tag names?

@Shazwazza you can get tag with git command and add it to a variable and then condition on this maybe?

If your build is triggered by a tag when you have ie.:

trigger:
  branches:
    include:
    - refs/heads/development
    - refs/heads/master
    - refs/tags/release-v*
    exclude:

then the ['Build.SourceBranch'] will be the name of the tag, ie.: refs/tags/release-v1

So the condition will work. I'm using it this way to only trigger a certain stage for commits, which are tagged.

How do you use this condition for the job if you could share the syntax? @sitereactor

Currently,

I am defininging a variable
- name: is_newtag value: $[eq(variables['Build.SourceBranch'], '$(VERSION_TAG)')]

and then using it as a condition for a certain job
condition: and(succeeded(), eq(variables['is_pr'], 'False'), eq(variables.is_main, 'True'), eq(variables.is_newtag, 'True'))

@kyawza-sps I'm not sure if this is what you are looking for, but here is a stage where I use a condition for the Source Branch


  - stage: deploy_live
    displayName: Deploy code to Live  
    condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/release-'))
    variables:
      environment_name: live
      service_connection: "Live Connection"
    jobs:
      - template: deploy.yml
        parameters:
          environment_name: ${{ variables.environment_name }}
          service_connection: ${{ variables.service_connection }}

Thank you @sitereactor. What you shared is what I was looking for.

Our repo release start with a version numbers so (e.g 0.1.19, 0.1.20), I am not certain if I can go with startsWith or go with eq against a versionTag. Will test if that work. I also don't want to manually having to change the version number if there is a major bump so starts with 0.1 might not be ideal.

Your naming scheme fits in really well with your setup.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

letmaik picture letmaik  Â·  3Comments

EM1L picture EM1L  Â·  3Comments

csutorasr picture csutorasr  Â·  3Comments

sevaa picture sevaa  Â·  3Comments

Naphier picture Naphier  Â·  3Comments