This is your script
echo foo > bar.txt
sudo chown root bar.txt
sudo chmod 600 bar.txt
If the user that runs the agent is nor root does not have access to the bar.txt file, only root can read this file, so if you use a no root user to try to archive the artifacts you see this error.
ERROR: Failed to archive artifacts: bar.txt
java.io.EOFException: Unexpected end of ZLIB input stream
at com.jcraft.jzlib.InflaterInputStream.fill(InflaterInputStream.java:186)
at com.jcraft.jzlib.InflaterInputStream.read(InflaterInputStream.java:106)
at org.apache.commons.compress.utils.IOUtils.readFully(IOUtils.java:160)
at org.apache.commons.compress.utils.IOUtils.readFully(IOUtils.java:134)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.readRecord(TarArchiveInputStream.java:419)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getRecord(TarArchiveInputStream.java:388)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:269)
at hudson.FilePath.readFromTar(FilePath.java:2351)
Also: Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to local
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1737)
at hudson.remoting.UserResponse.retrieve(UserRequest.java:313)
at hudson.remoting.Channel$2.adapt(Channel.java:986)
at hudson.remoting.Channel$2.adapt(Channel.java:983)
at hudson.remoting.FutureAdapter.get(FutureAdapter.java:59)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2280)
at jenkins.model.StandardArtifactManager.archive(StandardArtifactManager.java:61)
at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:245)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1752)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
java.io.IOException: This archives contains unclosed entries.
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.finish(TarArchiveOutputStream.java:225)
at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.close(TarArchiveOutputStream.java:241)
at hudson.util.io.TarArchiver.close(TarArchiver.java:127)
at hudson.FilePath.writeToTar(FilePath.java:2337)
at hudson.FilePath.access$2300(FilePath.java:208)
at hudson.FilePath$45.invoke(FilePath.java:2272)
at hudson.FilePath$45.invoke(FilePath.java:2268)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2816)
at hudson.remoting.UserRequest.perform(UserRequest.java:210)
at hudson.remoting.UserRequest.perform(UserRequest.java:53)
at hudson.remoting.Request$2.run(Request.java:364)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused: java.util.concurrent.ExecutionException
at hudson.remoting.Channel$2.adapt(Channel.java:988)
at hudson.remoting.Channel$2.adapt(Channel.java:983)
at hudson.remoting.FutureAdapter.get(FutureAdapter.java:59)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2280)
Caused: java.io.IOException: Failed to extract /tmp/workspace/test/transfer of 1 files
at hudson.FilePath.readFromTar(FilePath.java:2373)
at hudson.FilePath.copyRecursiveTo(FilePath.java:2277)
at jenkins.model.StandardArtifactManager.archive(StandardArtifactManager.java:61)
at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:245)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1752)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Build step 'Archive the artifacts' changed build result to FAILURE
The solution it is to give the right permission to the files in order to allow the agent process to archive the file, if you need a set of specific permissions on files, you should package the files before archiving, theb you can archive the result zip file. |