gitignore用于jenkins备份,包括构建工件,不包括构建目录

时间:2018-09-05 12:33:00

标签: git

因此,我尝试在后台使用git设置自动jenkins备份。 现在,我真的很想备份存档的结果。但是,我不需要/不需要其余的构建信息(很多)。

我将.gitignore设置为:

/*snip*/
jobs/**/builds/*
/*snip*/

但是我需要添加(或者我读到)的内容是这样的:

/*snip*/
jobs/**/builds/*
!jobs/**/builds/**/archive/*
/*snip*/

但这不起作用。它将所有内容忽略在/ builds / *下。如何取消忽略builds / buildnumber /文件夹中的存档文件夹?

1 个答案:

答案 0 :(得分:2)

Note from the gitignore documentation:

It is not possible to re-include a file if a parent directory of that file is excluded.

The problem with your pattern is that jobs/**/builds/* is excluding all of the numeric build directories and all directories under them, so your subsequent negation has no effect because the exclude pattern is a parent of the archive directory.

What you need to do is adjust the pattern to exclude the files/directories from within the individual numeric build directory, which still allows you to re-include the archive directory

jobs/**/builds/*/*
!jobs/**/builds/*/archive

Explanation:

  1. Exclude all files/directories inside jobs/<job-name>/builds/<build-no>/
    • Note the use of the * instead of **; the single asterisk only matches a single directory instead of expanding to exclude all nested subdirectories
  2. Re-include jobs/<job-name>/builds/<build-no>/archive (and any files/directories therein)

I've verified that these patterns should work for both freestyle and multibranch pipeline style jobs.

相关问题