Search code examples
azureazure-devopsazure-pipelinespipeline

Azure Pipelines - Packages are using versioning from pre-release task rather than release task despite pre-release task not running


Basically, I have a pipeline that is pushing packages to a feed. I have it set to use environment variables to create a pre-release package version if the source is development branch. Otherwise, it should read the versioning from the .csproj file if the source branch is master. According to the logs, the correct steps are running. However, when I get to the push step, I notice in the logs that it's pushing a pre-release rather than the release to the feed despite the pre-release task not even running. What's going on and how can I fix this? Here are the tasks in question:

variables:
  buildConfiguration: 'Release'
  isDev: $[eq(variables['Build.SourceBranch'], 'refs/heads/development')]
  isMain: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]

- task: DotNetCoreCLI@2
  displayName: "Dotnet Pack"
  condition: eq(variables.isMain, true)
  inputs:
    command: 'pack'
    arguments: '--configuration $(buildConfiguration)'
    packagesToPack: '**/*.csproj'
    nobuild: true
    versioningScheme: 'off'

- task: DotNetCoreCLI@2
  displayName: "Dotnet Pack (pre-release)"
  condition: eq(variables.isDev, true)
  inputs:
    command: 'pack'
    arguments: '--configuration $(buildConfiguration)'
    packagesToPack: '**/*.csproj'
    nobuild: true
    versioningScheme: byEnvVar
    versionEnvVar: PackageVersion

- task: NuGetCommand@2
  displayName: 'Nuget Push to Feed'
  inputs:
    command: 'push'
    feedsToUse: 'select'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '*cleared*'
    versioningScheme: 'off'
    allowPackageConflicts: true


Solution

  • when I get to the push step, I notice in the logs that it's pushing a pre-release rather than the release to the feed despite the pre-release task not even running.

    Based on my test, I could reproduce this issue when I run the pipeline with your Yaml Pipeline sample.

    enter image description here

    The root cause of this issue is the name of the environment variable PackageVersion.

    When the environment variable name is PackageVersion, this issue will exist.

    To solve this issue, you could change the environment variable name.

    - task: DotNetCoreCLI@2
      displayName: "Dotnet Pack (pre-release)"
      condition: eq(variables.isDev, true)
      inputs:
        command: 'pack'
        arguments: '--configuration $(buildConfiguration)'
        packagesToPack: '**/*.csproj'
        nobuild: true
        versioningScheme: byEnvVar
        versionEnvVar: Package1
    

    Then it will work fine.

    enter image description here