Jenkins save artifact when build failed

Danny Gloudemans picture Danny Gloudemans · Jun 7, 2012 · Viewed 10.5k times · Source

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> 

Answer

malenkiy_scot picture malenkiy_scot · Jun 7, 2012

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.