azure-devopsazure-pipelinesazure-pipelines-yaml

Azure Dev-Ops - Stages and Variable Groups


I am working with an azure devops environment that I inherited, and have this problem.

I created a new stage by cloning another. I also created a new variable group to be used by this new stage, which has target server names.

The problem I have is that when I deploy this new stage, it deploys to the original server, not the new one (as if it's still using the same old variable group).

I guess I am having difficulty associating the new stage with the proper scope? What ties the new stage to the new variable group?

What am I missing? (Here is my pipeline yml file)

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- develop
- release-*

variables:
  solution: '**/*.sln'
  buildPlatform: 'x64'
  buildConfiguration: 'Release'

jobs:
- job : Backend
  pool:
    name: 'Default'
  steps:
  - task: NuGetToolInstaller@1
    inputs:
      versionSpec: '6.9.1' # string. Version of NuGet.exe to install.

  - task: NuGetCommand@2
    inputs:
      command: 'restore'
      restoreSolution: '$(solution)'
      feedsToUse: 'select'
      noCache: true

  - task: VSBuild@1
    displayName: 'Build Web'
    inputs:
      solution: '$(solution)'
      msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'
      vsVersion: '17.0' # Optional. Options: latest, 16.0, 15.0, 17.0
      
  - task: VSTest@2
    inputs:
      testSelector: 'testAssemblies'
      testAssemblyVer2: |
        **\*test*.dll
        !**\*TestAdapter.dll
        !**\obj\**
      searchFolder: '$(System.DefaultWorkingDirectory)'
      vstestLocationMethod: 'location'
      vstestLocation: 'C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\TestPlatform'
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'
      otherConsoleOptions: '/Platform:x64'

  - task: ArchiveFiles@2
    displayName: 'Zip Service'
    inputs:
      rootFolderOrFile: '$(Build.SourcesDirectory)/src/jobs/winservice/IAM.PestApp.Service/bin/$(buildConfiguration)'
      includeRootFolder: false
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/winservice.zip'
      replaceExistingArchive: true

  - task: ArchiveFiles@2
    displayName: 'Zip IAMPestAppService DB'
    inputs:
      rootFolderOrFile: 'dbs/IAMPestAppService/bin/$(buildConfiguration)'
      includeRootFolder: false
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/IAMPestAppService.zip'
      replaceExistingArchive: true

  - task: ArchiveFiles@2
    displayName: 'Zip IAMPestApp DB'
    inputs:
      rootFolderOrFile: 'dbs/IAMPestApp/bin/$(buildConfiguration)'
      includeRootFolder: false
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/IAMPestApp.zip'
      replaceExistingArchive: true
      
  - task: ArchiveFiles@2
    displayName: 'Zip IAMPowerBI DB'
    inputs:
      rootFolderOrFile: 'dbs/IAMPowerBI/bin/$(buildConfiguration)'
      includeRootFolder: false
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/IAMPowerBI.zip'
      replaceExistingArchive: true
      
  - task: CopyFiles@2
    displayName: 'Copy PBIX Files to: $(Build.ArtifactStagingDirectory) '
    inputs:
      SourceFolder: 'src/IAM.PestApp.UI'
      Contents: '**/*.pbix'
      TargetFolder: '$(Build.ArtifactStagingDirectory)'
      
  - task: CopyFiles@2
    displayName: 'Copy Azure Deploy Files To Staging Directory'
    inputs:
      Contents: |
        build/azuredeploy.json
        build/azuredeploy.parameters.json
      TargetFolder: '$(Build.ArtifactStagingDirectory)'
      OverWrite: true

  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(build.artifactStagingDirectory)'
      artifact: 'IAM.PestApp.UI'
      publishLocation: 'pipeline'

- job: Frontend
  pool: 
    vmImage: 'windows-latest'
  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '3.x' 
      addToPath: true 
      architecture: 'x64' # Options: x86, x64 (this argument applies only on Windows agents)

  - task: NodeTool@0
    displayName: Install Node.js
    inputs:
      versionSpec: '14.x'  #'Your version e.g. 14.x'

  - task: Npm@1
    displayName: 'NPM - Install React Project'
    inputs:
      command: 'install'
      workingDir: 'src/ui'

  - task: Npm@1
    displayName: 'NPM - Build React Project'
    inputs:
      command: 'custom'
      workingDir: 'src/ui'
      customCommand: 'run build'

  - task: Npm@1
    displayName: 'NPM - Test React Project'
    inputs:
      command: 'custom'
      workingDir: 'src/ui'
      customCommand: 'run testOnce'

  - task: ArchiveFiles@2
    displayName: 'Zip React Project'
    inputs:
      rootFolderOrFile: 'src/IAM.PestApp.UI/Content/COW'
      includeRootFolder: true
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/COW.zip'
      replaceExistingArchive: true

  - task: PublishPipelineArtifact@1
    displayName: 'Publish Artifacts'
    inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)'
      artifact: 'FrontEnd'
      publishLocation: 'pipeline'

Update Here is what I see when I try to edit my pipeline, but again, this is the build pipeline: enter image description here

In that view, the 'variables button only allows my set set individual variables for the pipeline.

I need to select a release before it let's me see the stages. enter image description here Here are my variable groups. The one I am targeting is the production-flex group. enter image description here


Solution

  • Regarding Azure classic release pipelines, variable groups can be managed in the Variables > Variable Groups section of the release:

    Release pipeline - variable groups

    Please note that the scope of a variable or variable group can be set to the entire release or, as an alternative, one or more stages:

    Variable group - edit

    Setting the scope:

    Variable group - change scope

    The above applies to individual pipeline variables as well.

    See Use variable groups in Classic pipelines for more details.