Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PublishPipelineArtifact .artifact ignore not recognized

I am using Azure DevOps build pipeline to send a artifact over to a release pipeline. My build pipeline is as follows:

  1. Install Node JS with NodeTool@0
  2. Run a Script Command that runs npm install and then runs the test suite.
  3. Post the code coverage results via PublishCodeCoverageResults@1
  4. Publish artifact with PublishPipelineArtifact@1 and targetPath: '$(Pipeline.Workspace)' as the artifact directory.

When I originally did this without using the code coverage part, IE not installing node, the files sent over were 257 and was a little over 25MB. Completely workable and quick.

However when I installed node and ran code coverage the files exploded to 750MB, which is understandable - but is way too much to transfer as an artifact IMHO.

So, looking at a solution I found this: https://docs.microsoft.com/en-us/azure/devops/artifacts/reference/artifactignore?view=azure-devops

And, I added this into the root of the repo.

Example

However, this file seems to have not made a difference using the PublishPipelineArtifact@1 at all. No matter what I did, all the files from the Workspace were used as the artifact.

What did work though, was physically deleting the files in the build process.

I realize that is a lot of detail for a question, but I would like to know if the .artifactignore file actually works with this build pipeline?

Is there a way I can use the artifact ignore file properly, and not worry about deleting files before creating the artifact?

Tried to change the target directory in the PublishPipelineArtifact@1 task.

Here is the current working YAML:

# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run test:devops
  displayName: 'npm install and test'

- task: PublishCodeCoverageResults@1
  displayName: 'publish ng code coverage results'
  condition: succeededOrFailed()
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: 'coverage/cobertura-coverage.xml'
    reportDirectory: coverage
    failIfCoverageEmpty: true

- task: DeleteFiles@1
  inputs:
    SourceFolder: '$(Pipeline.Workspace)/s'
    Contents: |
      node_modules
      coverage

- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(Pipeline.Workspace)'
    artifact: 'my-artifact'

The expected results would be a smaller artifact file that still posts code coverage and installs node.

like image 671
kirikintha Avatar asked Jul 15 '19 15:07

kirikintha


2 Answers

The .artifactignore should be in the same directory as defined as target path of the publish pipelines artifact task (not only in the root of the repo like azure-pipelines.yml).

Is not in the docs and there is an issue about it here. also check here.

like image 156
Shayki Abramczyk Avatar answered Sep 28 '22 17:09

Shayki Abramczyk


Ok, so I used the information from Shayki Abramczyk - which is the correct answer - but wanted to put a working yaml together for everyone. I had to copy my .artifactignore from the repo, which is: $(Pipeline.Workspace)/s to the root which is $(Pipeline.Workspace)

As soon as I did this - it showed results. As soon as I adjusted the artifact ignore file, the output reduced from 750+MB to 2.3MB and processed in 8 seconds.

Working YAML:

- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run test
  displayName: 'npm install and test'

- task: PublishCodeCoverageResults@1
  displayName: 'publish ng code coverage results'
  condition: succeededOrFailed()
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: 'coverage/cobertura-coverage.xml'
    reportDirectory: coverage
    failIfCoverageEmpty: true

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Pipeline.Workspace)/s'
    Contents: '**/.artifactignore'
    TargetFolder: '$(Pipeline.Workspace)'

- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(Pipeline.Workspace)'
    artifact: 'my-artifact'

FYI - this is being built for angular, so this is the artifact ignore file I used. Your mileage will vary based on your project.

**/dist
**/node_modules
**/coverage
**/.git
like image 29
kirikintha Avatar answered Sep 28 '22 17:09

kirikintha