Search code examples
azure-devopsartifact

Exclude a folder with .artifactignore


I'm building a pipeline where my staging directory looks like this:

.
└── a
    ├── b
    │   ├── c   <-- exclude everything under this
    │   │   └── d
    │   │       ├── big_file_1
    │   │       └── big_file_2
    │   ├── file_1
    │   └── file_2
    ├── file_3
    └── file_4

What I want is to exclude everything under c from my artifact. The files under c can be deeply nested and the number of levels is unpredictable. I learned that .artifactignore, while advertising that it works like .gitignore, is anything but. If I want to exclude c, all I had to do in .gitignore is:

**/c

I tried that, plus countless other patterns in .artfifactignore but can't make it to work. Here's a YAML pipeline if you want to replicate the problem:

steps:
  - bash: |
      mkdir -p a/b/c/d
      touch a/b/c/d/big_file_1
      touch a/b/c/d/big_file_2

      touch a/b/file_1
      touch a/b/file_2
      touch a/file_3
      touch a/file_4

      echo > .artifactignore <<EOF
      **/c
      **/c/*
      **/c/**
      **/c/**/*
      a/b/c/**
      **/big*
      EOF

      tree
    workingDirectory: $(Build.StagingDirectory)

  - publish: $(Build.StagingDirectory)
    name: drop
    displayName: Publish

None of the patterns worked! How am I supposed to exclude c directory with .artifactignore?


Solution

  • I have done some very minor ("cat" instead of "echo") updates in your pipeline and it works fine for me.

    My pipeline:

    trigger:
      - none
    
    stages:
      - stage: first
        jobs: 
         - job: firstJob
           continueOnError: false
           steps:
             - bash: |
                 mkdir -p a/b/c/d
                 touch a/b/c/d/big_file_1
                 touch a/b/c/d/big_file_2
    
                 touch a/b/file_1
                 touch a/b/file_2
                 touch a/file_3
                 touch a/file_4
    
                 cat > .artifactignore <<EOF
                 **/c
                 EOF
                 
                 tree
               workingDirectory: $(Build.StagingDirectory)
             - publish: $(Build.StagingDirectory)
               name: drop
               displayName: Publish
    

    Output for Tree:

    enter image description here


    Published artifact:

    enter image description here


    References: