4

I want to Archive the artifacts of my program, but when the build failes he doesn't save the artifacts. Why is this?

Because I only want to read the artifact when the job failed!

Thanks for your response!

--

Always when the job fails, I didn't get the artifact. I test it in very small jobs:

Empty batch file + artifact a file, Result: Job Succesfull, Artifact: succesfull

Exit 1 in batch file + artifact a file, Result: Job fails, Artifact: didn't do anything

config.xml file of the job:

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description></description>
  <keepDependencies>false</keepDependencies>
  <properties/>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers class="vector"/>
  <concurrentBuild>false</concurrentBuild>
  <customWorkspace>C:\test\</customWorkspace>
  <builders>
    <hudson.tasks.BatchFile>
      <command>exit 1</command>
    </hudson.tasks.BatchFile>
  </builders>
  <publishers>
    <hudson.tasks.ArtifactArchiver>
      <artifacts>tomcat\logs\tomcat.log</artifacts>
      <latestOnly>false</latestOnly>
    </hudson.tasks.ArtifactArchiver>
  </publishers>
  <buildWrappers/>
</project> 
malenkiy_scot
  • 16,415
  • 6
  • 64
  • 87
Danny Gloudemans
  • 2,597
  • 7
  • 39
  • 57
  • Maybe your configuration does not produce the files to be archived before the build fails? As soon as teh build fails the post-build steps are executed. – anhoppe Jun 07 '16 at 12:18

2 Answers2

5

Artifacts are archived regardless of whether the build failed or not. Make sure of the following:

  • You are looking at the actual last build artifacts, not 'Last Successful Build' artifacts.
  • That a build step that produces the artifacts (or copies them into your workspace for archiving) actually runs - chances are it won't run if it is supposed to run after the failure. In that case you need a workaround that depends on your specific situation.

Also take a look at this related question.

Community
  • 1
  • 1
malenkiy_scot
  • 16,415
  • 6
  • 64
  • 87
  • I swear to God, sometimes when the build failed, he doesn't archive the artifact! I don't know why.. – Danny Gloudemans Jun 08 '12 at 06:59
  • Ok, I think the only way I can help you is if you provide a minimal job (i.e. `config.xml`) that reproduces your problem: copy your job, and then one by one get rid of all the parts that are non-essential to the problem at hand (by the way, it's quite probable that while doing it you'll realize what the problem is). You can also try the following: create a job (shell/batch build step) that creates a file in the workspace and then fails (`exit 1`). As a post-build step try to archive that file as an artifact. See if it does it. – malenkiy_scot Jun 08 '12 at 08:09
  • I created a minimal job. The only thing I did was start a empty batch file and archive the file. The job went succesfull and I get the artifact. I set exit 1 in the batch file and archive the file. And the job went wrong and doesn't get the artifact. I test this in some other ways. But always when the job fails, I didn't get the artifact! – Danny Gloudemans Jun 11 '12 at 09:28
  • 1
    Can you please post that `config.xml` so I can play with it? – malenkiy_scot Jun 11 '12 at 09:31
  • I added the config.xml in de first post – Danny Gloudemans Jun 11 '12 at 09:36
  • 1
    I created `C:\test\tomcat\logs\tomcat.log`. It archives it fine. Seems that the problem is with Tomcat. I don't run Jenkins under Tomcat and don't know much about its quirks. So maybe the problems is that Tomcat removes the log file before the build (Jenkins surely does not) and then does not flush it (or does not create it at all) before the build fails. – malenkiy_scot Jun 11 '12 at 10:11
  • I'm sure that the file is created and Jenkins deletes the file. Because when I don't use the Delete workspace when build is done task, what is the last task to do, the file still exists. – Danny Gloudemans Jun 11 '12 at 10:55
  • 1
    I already find my fault. You only find the artifact in the job status. Not on the 'homepage' of the job. There you only find the Last Successful Artifacts, and not the ones that failed. Is it possible to change that? – Danny Gloudemans Jun 11 '12 at 10:59
  • Probably the easiest way to add last artifacts to your build is to add job description ('add description' link on the job page) with something like this: `Last Artifacts`. – malenkiy_scot Jun 11 '12 at 11:11
  • No problem - we are all only *carbon-based, bipedal life forms descended from an ape* :) – malenkiy_scot Jun 11 '12 at 11:49
2

In "Archive the Artifact" step, click on Advanced button. Uncheck "Archive artifacts only if build is successful" So even if your unit tests failed, you will have the artifacts archived.

simonso
  • 595
  • 1
  • 8
  • 19