3

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?

Mike Henderson
  • 2,028
  • 1
  • 13
  • 32
  • Did you look at the `.artifactignore` documentation? *To assure the proper execution, .artifactignore file should be checked into the root of the repository.* – Daniel Mann Dec 17 '21 at 00:24
  • 1
    Plenty of people, include a Microsoft MVP, says that I should place it at the target path of the `publish` task: https://www.jfe.cloud/control-pipeline-artifacts-with-artifactignore-file/ – Mike Henderson Dec 17 '21 at 00:28
  • I just tried placing it at the root of the repo. No difference – Mike Henderson Dec 17 '21 at 00:30

1 Answers1

2

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:

Tejas Nagchandi
  • 442
  • 4
  • 11
  • Hm... interesting that `cat` fixes the problem but while `echo` blew it. I will mark this as the accepted answer – Mike Henderson Dec 19 '21 at 02:47
  • I would suggest you to read the third reference [link](https://stackoverflow.com/questions/7875540/how-to-write-multiple-line-string-using-bash-with-variables) for clear explanation. – Tejas Nagchandi Dec 19 '21 at 23:19