Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 506
Mike Henderson Avatar asked Oct 19 '25 03:10

Mike Henderson


1 Answers

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:

  • https://learn.microsoft.com/en-us/azure/devops/artifacts/reference/artifactignore?view=azure-devops
  • https://git-scm.com/docs/gitignore
  • How to write multiple line string using Bash with variables?
like image 189
Tejas Nagchandi Avatar answered Oct 21 '25 11:10

Tejas Nagchandi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!