0
votes

I managed to have my pipeline triggered when I push a tag to the repo. The tag is always is the format "v(Major).(Minor).(Release)(-alpha)".

How can I get that information from the tag and set is as the package version?

EDIT 1:
The command git tag -a 1.0.1 will create the tag that will trigger the pipeline and I want the nugget package version to be "1.0.1" like the tag

3

3 Answers

2
votes

You'll probably have to do some parsing and error handling so this runs for just tags, but you can source and parse the value from Build.SourceBranch variable as shown in the documentation:

The branch of the triggering repo the build was queued for. Some examples:

  • Git repo branch: refs/heads/master
  • Git repo pull request: refs/pull/1/merge
  • TFVC repo branch: $/teamproject/main
  • TFVC repo gated check-in: Gated_2016-06-06_05.20.51.4369;[email protected]
  • TFVC repo shelveset build: myshelveset;[email protected]
  • When your pipeline is triggered by a tag: refs/tags/your-tag-name

When you use this variable in your build number format, the forward slash characters (/) are replaced with underscore characters _).

Note: In TFVC, if you are running a gated check-in build or manually building a shelveset, you cannot use this variable in your build number format.

1
votes

This can be done without doing parsing and error handling with the following YAML:

trigger:
  tags:
    include:
    - 0.*
    - 1.*
    - 2.*
    - 3.*
    - 4.*
    - 5.*
    - 6.*
    - 7.*
    - 8.*
    - 9.*

pool: 'LocalWindows'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
   
- task: NuGetCommand@2
  inputs:
    command: 'pack'
    packagesToPack: '**/Source/*.vbproj'
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'BUILD_SOURCEBRANCHNAME'
    includeSymbols: true

The special thing is, that you must have a trigger which only listens on tags and then you can use the envvar BUILD_SOURCEBRANCHNAME.

You can adjust the tag-includes as you wish.

0
votes

Inside the pipeline, you have an option called tag format, where you can see the package version.

Please take a look at the below screenshot :

Pipelines Tag Format

Artifact