Home > database >  Jenkins Zip file missing .gitignore and .gitattributes
Jenkins Zip file missing .gitignore and .gitattributes

Time:03-08

I'm attempting to use the archive functionality but I'm not able to download all the files. For example, in Jenkins I see: enter image description here

However, after clicking the link to download all the files as a zip, then unzipping the files, I see: enter image description here

I'm not sure why the .gitignore and .gitattributes are missing from the zip file when I download it but are present in the artifacts listed in Jenkins.

I use the following command to archive the artifacts:

archiveArtifacts artifacts: "portfolios-deployment_${PACKAGE_VERSION}/**/*", onlyIfSuccessful: true, defaultExcludes: false

CodePudding user response:

The archiveArtifacts option:

Archives the build artifacts (for example, distribution zip files or jar files) so that they can be downloaded later. Archived files will be accessible from the Jenkins webpage.

By that, it means it takes a copy of the artifacts from the workspace and stores them alongside the build logs on the controller. It is expected the workspace is ephemeral or its contents will be overwritten on next iteration, so they are preserved along with the logs, until the logs are deleted.

archiveArifacts has an Advanced ... option:
[ X ] Use default excludes

If you expand the help, you'll see the details:

Artifact archiver uses Ant org.apache.tools.ant.DirectoryScanner which excludes by default the following patterns: /%*%,/.git/,/SCCS,/.bzr,/.hg/,/.bzrignore,/.git,/SCCS/,/.hg,/.#*,/vssver.scc,/.bzr/,/._*,/##,**/~,/CVS,/.hgtags,/.svn/,/.hgignore,/.svn,/.gitignore,/.gitmodules,/.hgsubstate,/.gitattributes,/CVS/,/.hgsub,/.DS_Store,**/.cvsignore

This option allows to enable or disable the default Ant exclusions.

Turn that off and it should pick them up, but may also include much more. Consider using a pattern in:
Files to archive [ **,.gitignore,.gitattributes ].

Downloading

However, the "(all files in zip)" is part of the Jenkins UI standard DirectoryBrowserSupport capability. Any directory displayed within the "Browse Workspace" has the option displayed to download the content of that page. That "(all files in zip)" is also provided by the org.apache.tools.zip capability which would use the same Ant FileSet excludes. This applies equally to both the Browse Workspace and Browse Artifacts pages. But, as this capability is built into the Jenkins UI layer, there does not seem to be any overrides for the Artifacts. You just need to download them manually individually.

It may be worth filing a ticket (for component:core, label archive) such that the download "all files in zip" respect the content as displayed within "Browse Artifacts". (That would not be desirable behaviour for the workspace itself).


More generally:

As the help says, it's based on default Ant exclusions (a list which is modifiable). See also Ant FileSet for other conventions.

Ant is in turn based in unix conventions, where files beginning with a dot "." are "hidden files", typically considered "configuration files' and not generally of interest. The Ant list is more specifically to exclude configuration files which are part of common source control systems (there'd be no need to continually archive .git for example). "dot files" do not show up by default in ls -l; you need to run ls -la (all). That logic also extend to other commands.

Also note that while unix is case sensitive, the default for Ant is "no" to case sensitivity for includes/excludes, which may cause issues if (for some silly reason) you have Foo.java and foo.java, but which is then enabled by default in the archiveArtifacts option.

  • Related