0

I created a yaml-based, multi-stage pipeline in Azure DevOps.

variables:
  versionPrefix: '7.1.0.'
  versionRevision: $[counter(variables['versionPrefix'], 100)]
  version: $[format('{0}{1}',variables['versionPrefix'],variables['versionRevision'])]
  solution: '**/product.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'

name: $(version)_$(Date:yyyyMMdd)$(Rev:.r)

stages:
- stage: Build
  pool: Default
  jobs:
  - job: Build
    displayName: Build
    steps:
      - task: NuGetToolInstaller@1
      - task: NuGetCommand@2
        inputs:
          restoreSolution: '$(solution)'
      - task: VersionAssemblies@2
        displayName: Version Assemblies
        inputs:
          Path: '$(Build.SourcesDirectory)'
          VersionNumber: '$(version)'
          InjectVersion: true
          FilenamePattern: 'AssemblyInfo.*'
          OutputVersion: 'OutputedVersion'
      - task: VSBuild@1
        displayName: Build product
        inputs:
          solution: '$(solution)'
          platform: '$(buildPlatform)'
          configuration: '$(buildConfiguration)'
          maximumCpuCount: true

- stage: Deploy
  dependsOn: Build
  pool: Default
  jobs:
  - deployment: Deployment
    displayName: DeployA
    environment: 7-1-0
    strategy:
      runOnce:
        deploy:
          steps:
          - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "Deployed"

As shown above, the pipeline includes a deployment stage that references an environment named '7-1-0'. After the pipeline runs, a deployment is displayed in the UI for that environment. However, under that environment both the Changes and Workitems pages are empty. I confirmed there are new changes that have not previously been deployed to this environment. Why?

Note the deployment stage doesn't actually do anything. We're doing the actual deployment manually, but were hoping to track the changes to the environment via DevOps. Also, we haven't defined any resources for the environment. I couldn't find anything stating it was required to have a resource defined for traceability of commits and work items.

UPDATE 1

Per @Leo-Liu-MSFT suggestion below, I updated the pipeline to publish an artifact. Note that the build runs on a self-hosted agent. However, I'm still not getting any results in Environment Changes and Workitems.

variables:
  versionPrefix: '7.1.0.'
  versionRevision: $[counter(variables['versionPrefix'], 100)]
  version: $[format('{0}{1}',variables['versionPrefix'],variables['versionRevision'])]
  solution: '**/product.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'

name: $(version)_$(Date:yyyyMMdd)$(Rev:.r)

stages:
- stage: Build
  pool: Default
  jobs:
  - job: Build
    displayName: Build
    steps:
      - task: NuGetToolInstaller@1
      - task: NuGetCommand@2
        inputs:
          restoreSolution: '$(solution)'
      - task: VersionAssemblies@2
        displayName: Version Assemblies
        inputs:
          Path: '$(Build.SourcesDirectory)'
          VersionNumber: '$(version)'
          InjectVersion: true
          FilenamePattern: 'AssemblyInfo.*'
          OutputVersion: 'OutputedVersion'
      - task: VSBuild@1
        displayName: Build product
        inputs:
          solution: '$(solution)'
          platform: '$(buildPlatform)'
          configuration: '$(buildConfiguration)'
          maximumCpuCount: true
      - task: PowerShell@2
        inputs:
          targetType: 'inline'
          script: |
            New-Item -Path '$(build.artifactstagingdirectory)' -Name "testfile1.txt" -ItemType "file" -Value "Hello, DevOps!" -force
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)'
          ArtifactName: 'drop'
          publishLocation: 'FilePath'
          TargetPath: 'C:\a\p\\$(Build.DefinitionName)\\$(Build.BuildNumber)'

- stage: Deploy
  dependsOn: Build
  pool: Default
  jobs:
  - deployment: Deployment
    displayName: DeployA
    environment: 7-1-0
    strategy:
      runOnce:
        deploy:
          steps:
          - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "Deployed"

UPDATE 2

Per follow up suggestion from @Leo-Liu-MSFT, I created the following attempted publishing the artifact to Azure. I also simplified the yaml to use a Microsoft Hosted Agent. Note I did have the issue described here which is why I configured the deployment task they way I did with 'download: none'. I'm still not getting any Changes or Workitems in the environment.

variables:
  ArtifactName: drop

stages:
- stage: Build
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: ubuntu-latest
    steps:
      - task: CopyFiles@2
        displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)/Build'
          targetFolder: '$(build.artifactstagingdirectory)'

      - task: PublishBuildArtifacts@1
        displayName: 'Publish Artifact: drop'
        inputs:
          ArtifactName: $(ArtifactName)

- stage: Deploy
  dependsOn: Build
  pool:
   vmImage: ubuntu-latest
  jobs:
  - deployment: Deployment
    displayName: DeployA
    environment: 7-1-0
    strategy:
      runOnce:
        deploy:
          steps:
          - download: none
          - task: DownloadBuildArtifacts@0
            inputs:
                artifactName: $(ArtifactName)
                buildType: 'current'
                downloadType: 'single'
                downloadPath: '$(System.ArtifactsDirectory)'

FINAL UPDATE

Here's the working YAML. The final trick was to set download to current and specify the artifact name.

variables:
  ArtifactName: drop

stages:
- stage: Build
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: ubuntu-latest
    steps:
      - task: CopyFiles@2
        displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)/Build'
          targetFolder: '$(build.artifactstagingdirectory)'

      - task: PublishBuildArtifacts@1
        displayName: 'Publish Artifact: drop'
        inputs:
          ArtifactName: $(ArtifactName)

- stage: Deploy
  dependsOn: Build
  pool:
   vmImage: ubuntu-latest
  jobs:
  - deployment: Deployment
    displayName: DeployA
    environment: 7-1-0
    strategy:
      runOnce:
        deploy:
          steps:
          - download: current
            artifact: $(ArtifactName)
bkstill
  • 657
  • 1
  • 8
  • 15

1 Answers1

1

Why are the Changes and Workitems pages empty under an Environment in a multi-stage Azure Devops pipline?

You need to add publish build Artifacts task to publish build artifacts to Azure Pipelines.

Azure devops track the changes and workitems via REST API, then Azure devops passes this information to other environments by transferring files.

So, we need to publish the artifact to the Azure Pipelines so that the deploy stage could get those info when it is getting source.

As test, I just add the copy task and publish build artifact task in the build stage, like:

stages:
- stage: Build
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: ubuntu-latest
    steps:
      - task: CopyFiles@2
        displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)'
          targetFolder: '$(build.artifactstagingdirectory)'

      - task: PublishBuildArtifacts@1

        displayName: 'Publish Artifact: drop'

- stage: Deploy
  dependsOn: Build
  pool:
   vmImage: ubuntu-latest
  jobs:
  - deployment: Deployment
    displayName: DeployA
    environment: 7-1-0
    strategy:
      runOnce:
        deploy:
          steps:
          - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "Deployed"

The result:

enter image description here

Update:

I had to make a few updates to deal with an issue downloading the artifact. Still not getting any Changes or Workitems on the environment. I do appreciate your help!

That because you are disable the built-in download task instead of using DownloadBuildArtifacts task, which task do not have feature to fetch the commits and work items.

- download: none

You need delete above in your YAML. As I test your updated YAML without - download: none, it works fine.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    Does it matter what gets published as an artifact, or can it just be anything? Also, I'm using a self-hosted agent and am publishing the artifact to a local folder. Would that matter? – bkstill Mar 31 '20 at 14:44
  • @bkstill, It can be anything. Self-hosted agent also work fine. You can just test it by a simple sample, have a good day :). – Leo Liu Apr 01 '20 at 01:55
  • 1
    I created a sample and updated my question with it. Feels like I'm missing something obvious. – bkstill Apr 01 '20 at 15:53
  • @bkstill, I am afraid we could not set it in the local folder, have to publish build artifacts to **Azure Pipelines**.I am very sorry I ignored this question in your previous comments. – Leo Liu Apr 02 '20 at 05:50
  • 1
    See UPDATE 2 in my question. I attempted to make my YAML as close to the sample you posted. I had to make a few updates to deal with an issue downloading the artifact. Still not getting any Changes or Workitems on the environment. I do appreciate your help! – bkstill Apr 02 '20 at 18:13
  • Deleting '- download: none' results in the error '##[error]Could not find any pipeline artifacts in the build.' for me. What else could be different? – bkstill Apr 03 '20 at 17:49
  • I did finally get it to work. I had to specify - download: current and set the artifact name. See the final update in my post. – bkstill Apr 03 '20 at 18:36