azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Inconsistencies in build output when adding a test project

Open Joeghanoe opened this issue 2 years ago • 0 comments

Describe the issue

Hi, I have been using this library for a while now and got the request from my boss to implement unit tests into our exisiting azure functions projects. When I ran the CI pipeline (after adding set unit test projects) all files in the /cs folder were gone in the published artifacts. However the build output would be inconsistent and every 5 or so builds on the same branch I would get the correct output and go on with building the project.

Additional context

I got around this issue by adding a copy files task which copies all files from the bin folder to the root folder of the artifact.

To Reproduce

Steps to reproduce the behavior:

  1. Create new azure functions project
  2. Create Xunit project
  3. Disable Xunit in buildconfiguration for release as this caused conflicts as seen in: #306
  4. Create CI pipeline with Xunit test step
  5. Look at published artifact and see missing files (empty folders with missing files)

Expected behavior

When building the artifact the build output should be consistent and the same each and every time.

Screenshots

Left side what current artifact looks like, right side is what the artifact should look like. All files do exist on the left side but in the /bin folder which does not work when deploying the Azure Function to Azure using the AzureFunctionApp@1 step. image

Environment (please complete the following information, if applicable):

  • OS: Ubuntu latest pipeline
  • .NET6 LTS
  • Function V4

Current pipeline (with fix)

name : ci-pipeline.yml
trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'
  
stages:
- stage: Build
  displayName: Build solution
  
  jobs:  
  - job: Build
    displayName: Build and publish solution
    workspace:
      clean: all
      
    steps:
    - task: UseDotNet@2
      displayName: Use Dot Net Core 6.0.x
      inputs:
        packageType: 'sdk'
        version: '6.0.x'
    
    - task: DotNetCoreCLI@2
      displayName: 'Restore NuGet packages'
      inputs:
        command: restore
        projects: "**/*.csproj"

    - task: DotNetCoreCLI@2 
      displayName: 'Build API'
      inputs:
        command: build
        arguments: '--configuration $(buildConfiguration)'

    - task: DotNetCoreCLI@2  
      displayName: Run XUnit tests
      inputs:  
        command: test  
        projects: '**/*.Tests.csproj'  
        arguments: '--configuration $(buildConfiguration)'  

    - task: DotNetCoreCLI@2
      displayName: 'Create API Artifact'
      inputs:
        command: publish
        arguments: '--output $(Build.ArtifactStagingDirectory)'
        configuration: $(BuildConfiguration)
        publishWebProjects: false
        zipAfterPublish: false

    - task: DeleteFiles@1
      displayName: 'Remove runtimes folder'
      inputs:
        SourceFolder: $(Build.ArtifactStagingDirectory)/runtimes
        Contents: '*'
        RemoveSourceFolder: true

    # This is the current fix I came up with
    - task: CopyFiles@2
      inputs:
        sourceFolder: $(Build.ArtifactStagingDirectory)/bin
        contents: '**' 
        targetFolder: $(Build.ArtifactStagingDirectory)
    # Fix ends here

    - task: ArchiveFiles@2
      displayName: 'Zip API Artifact'
      inputs:
        rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true

    - task: PublishPipelineArtifact@1
      displayName: 'Publish API Artifact'
      inputs:
        targetPath: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' 
        artifactName: 'ArtifactNameHere'

Joeghanoe avatar Apr 13 '22 11:04 Joeghanoe