我正在使用继承的 azure DevOps 环境,并遇到此问题。
我通过克隆另一个阶段创建了一个新阶段。 我还创建了一个新的变量组供这个新阶段使用,它具有目标服务器名称。
我遇到的问题是,当我部署这个新阶段时,它会部署到原始服务器,而不是新服务器(就好像它仍在使用相同的旧变量组一样)。
我想我很难将新阶段与正确的范围联系起来? 新阶段与新变量组有何联系?
我错过了什么? (这是我的管道 yml 文件)
# 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'
在 YAML 管道中,您可以在各种范围内设置变量:
我遇到的问题是,当我部署这个新阶段时,它会部署到原始服务器
我怀疑您没有在正确的范围内引用变量组。
尝试在阶段或工作级别(理想情况下)设置每个变量组。您应该尽可能减少变量的范围。
示例:
trigger: none
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: ServerA
jobs:
- job: DeployToServerA
variables:
- group: server-a-variables # Use a variable group at the job level
# ....
- stage: ServerB
jobs:
- job: DeployToServerB
variables:
- group: server-b-variables # Use a variable group at the job level
# ....
有关更多详细信息,请参阅定义变量。
请注意,当您在多个作用域中设置同名变量时,将遵循以下优先级(最高优先级优先):
在同一作用域内设置同名变量时,last设置的值优先。
请参阅变量范围了解更多详细信息。