Skip to content

Inconsistencies in build output when adding a test project #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Joeghanoe opened this issue Apr 13, 2022 · 0 comments
Open

Inconsistencies in build output when adding a test project #418

Joeghanoe opened this issue Apr 13, 2022 · 0 comments

Comments

@Joeghanoe
Copy link

Joeghanoe commented Apr 13, 2022

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: Empty swagger when using v0.9.0 with solution that includes a test project #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 Joeghanoe changed the title Missing files in all bin folders in CI pipeline when adding a test project inconsistencies in build output when adding a test project Apr 14, 2022
@Joeghanoe Joeghanoe changed the title inconsistencies in build output when adding a test project Inconsistencies in build output when adding a test project Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant