Skip to content

[JENKINS-38005] Using archiveArtifacts with a non-matching pattern silently fails the build #17504

Closed

Description

@jenkins-infra-bot

If you happen to specify a pattern that doesn't match any files in the workspace, archiveArtifacts will silently fail the build.

Jenkinsfile

node {
    sh 'echo "lol"'
    
    archiveArtifacts artifacts: 'lol*.zip'
}

Console Output

Started by user admin
[Pipeline] node
Still waiting to schedule task
Waiting for next available executor
Running on Azure0907122157 in /home/azureuser/workspace/Experiments/bad-artifacts
[Pipeline] {
[Pipeline] sh
[bad-artifacts] Running shell script
+ echo lol
lol
[Pipeline] step
Archiving artifacts
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: FAILURE

archive step

In contrast, the use of the archive step (e.g. archive 'lol*.zip' in the above Jenkinsfile) will result in a silently successful build.


Originally reported by rtyler, imported from: Using archiveArtifacts with a non-matching pattern silently fails the build
  • assignee: abayer
  • status: Resolved
  • priority: Major
  • component(s): core
  • label(s): pipeline
  • resolution: Fixed
  • resolved: 2017-05-05T16:21:03+00:00
  • votes: 9
  • watchers: 22
  • imported: 2025-11-24
Raw content of original issue

If you happen to specify a pattern that doesn't match any files in the workspace, archiveArtifacts will silently fail the build.

Jenkinsfile

node {
    sh 'echo "lol"'
    
    archiveArtifacts artifacts: 'lol*.zip'
}

Console Output

Started by user admin
[Pipeline] node
Still waiting to schedule task
Waiting for next available executor
Running on Azure0907122157 in /home/azureuser/workspace/Experiments/bad-artifacts
[Pipeline] {
[Pipeline] sh
[bad-artifacts] Running shell script
+ echo lol
lol
[Pipeline] step
Archiving artifacts
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: FAILURE

archive step

In contrast, the use of the archive step (e.g. archive 'lol*.zip' in the above Jenkinsfile) will result in a silently successful build.

  • environment: Jenkins 2.7.3, Pipeline 2.3

Activity

  1. jenkins-infra-bot commented on Sep 7, 2016

    @jenkins-infra-bot
    Author
  2. jenkins-infra-bot commented on Sep 14, 2016

    @jenkins-infra-bot
    Author
    maxzilla:
    • Original comment link
    • Raw content of original comment:

      I raised the priority to 'Critical' because this makes very difficult to see where a large build actually failed.

      Also, I saw a similar behavior:

      archiveArtifacts 'target/test.data'

      fails only if the directory 'target' does not exist. If it exists but not the file 'test.data', then the build fails but the build step was successful.

    I raised the priority to 'Critical' because this makes very difficult to see where a large build actually failed.

    Also, I saw a similar behavior:

    archiveArtifacts 'target/test.data'

    fails only if the directory 'target' does not exist. If it exists but not the file 'test.data', then the build fails but the build step was successful.

  3. jenkins-infra-bot commented on Oct 19, 2016

    @jenkins-infra-bot
    Author
    maxzilla:
    • Original comment link
    • Raw content of original comment:

      Is there any progress on this issue?

      It would be really really great if there was a way to tell if archiveArtifacts worked or not! I have a job that builds a lot of stuff and has ~750 steps. It's totally impossible to find out where the pipeline failed in case archiveArtifacts failed, because every step is green and there's no output at all that points me to the correct place.

      My approach is now more a Poor Man's Debugger than a solution: I put masses of printlns in it which give me the current build result. But this doesn't necessarily mean that the error happened at that specific place if you build stuff in parallel.

      IMHO, archiveArtifacts should at least print out the amount of files it included. Also a return value containing the files or the number of files would be great. But instead of failing silently, I'd prefer an Exception.

    Is there any progress on this issue?

    It would be really really great if there was a way to tell if archiveArtifacts worked or not! I have a job that builds a lot of stuff and has ~750 steps. It's totally impossible to find out where the pipeline failed in case archiveArtifacts failed, because every step is green and there's no output at all that points me to the correct place.

    My approach is now more a Poor Man's Debugger than a solution: I put masses of printlns in it which give me the current build result. But this doesn't necessarily mean that the error happened at that specific place if you build stuff in parallel.

    IMHO, archiveArtifacts should at least print out the amount of files it included. Also a return value containing the files or the number of files would be great. But instead of failing silently, I'd prefer an Exception.

  4. jenkins-infra-bot commented on Oct 19, 2016

    @jenkins-infra-bot
    Author
    jglick:
    • Original comment link
    • Raw content of original comment:

      Just use allowEmptyArchive: true. See inline help in Pipeline Syntax.

      As to the lack of a message, I suspect the following would suffice:

      diff --git a/core/src/main/java/hudson/tasks/ArtifactArchiver.java b/core/src/main/java/hudson/tasks/ArtifactArchiver.java
      index ca1f154..9175e11 100644
      --- a/core/src/main/java/hudson/tasks/ArtifactArchiver.java
      +++ b/core/src/main/java/hudson/tasks/ArtifactArchiver.java
      @@ -242,7 +242,7 @@ public class ArtifactArchiver extends Recorder implements SimpleBuildStep {
                       }
                   } else {
                       Result result = build.getResult();
      -                if (result != null && result.isBetterOrEqualTo(Result.UNSTABLE)) {
      +                if (result == null || result.isBetterOrEqualTo(Result.UNSTABLE)) {
                           // If the build failed, don't complain that there was no matching artifact.
                           // The build probably didn't even get to the point where it produces artifacts. 
                           listenerWarnOrError(listener, Messages.ArtifactArchiver_NoMatchFound(artifacts));
      

    Just use allowEmptyArchive: true. See inline help in Pipeline Syntax.

    As to the lack of a message, I suspect the following would suffice:

    diff --git a/core/src/main/java/hudson/tasks/ArtifactArchiver.java b/core/src/main/java/hudson/tasks/ArtifactArchiver.java
    index ca1f154..9175e11 100644
    --- a/core/src/main/java/hudson/tasks/ArtifactArchiver.java
    +++ b/core/src/main/java/hudson/tasks/ArtifactArchiver.java
    @@ -242,7 +242,7 @@ public class ArtifactArchiver extends Recorder implements SimpleBuildStep {
     }
         } else {
     Result result = build.getResult();
    -if (result != null && result.isBetterOrEqualTo(Result.UNSTABLE)) {
    +if (result == null || result.isBetterOrEqualTo(Result.UNSTABLE)) {
         // If the build failed, don't complain that there was no matching artifact.
         // The build probably didn't even get to the point where it produces artifacts. 
         listenerWarnOrError(listener, Messages.ArtifactArchiver_NoMatchFound(artifacts));
    
  5. jenkins-infra-bot commented on Oct 19, 2016

    @jenkins-infra-bot
    Author
    jglick:
    • Original comment link
    • Raw content of original comment:

      From a script, it would probably also work to run

      currentBuild.result = 'STABLE'
      

      prior to running the archiver. (The result can only get worse, never better, but it can become nonnull.)

    From a script, it would probably also work to run

    currentBuild.result = 'STABLE'
    

    prior to running the archiver. (The result can only get worse, never better, but it can become nonnull.)

  6. jenkins-infra-bot commented on Oct 19, 2016

    @jenkins-infra-bot
    Author
    mike_kingsbury:
    • Original comment link
    • Raw content of original comment:

      Jesse, you're missing the point. Yes, once someone recognizes the problem, it can be worked around. Until that point, they are left with a failed build and no useful information as to its cause. Hence the request for additional output from archiveArtifacts.

    Jesse, you're missing the point. Yes, once someone recognizes the problem, it can be worked around. Until that point, they are left with a failed build and no useful information as to its cause. Hence the request for additional output from archiveArtifacts.

  7. jenkins-infra-bot commented on Oct 19, 2016

    @jenkins-infra-bot
    Author
    jglick:
    • Original comment link
    • Raw content of original comment:

      you're missing the point

      I do not think I am missing anything. Hence my suggested patch above.

      (The ArtifactArchiver.NoMatchFound text should probably also suggest enabling the allowEmptyArchive mode—a later addition—if the lack of a match is not a bug.)

    you're missing the point

    I do not think I am missing anything. Hence my suggested patch above.

    (The ArtifactArchiver.NoMatchFound text should probably also suggest enabling the allowEmptyArchive mode—a later addition—if the lack of a match is not a bug.)

  8. jenkins-infra-bot commented on Oct 19, 2016

    @jenkins-infra-bot
    Author
    mike_kingsbury:
    • Original comment link
    • Raw content of original comment:

      My apologies, I misunderstood the intent of the patch.

    My apologies, I misunderstood the intent of the patch.

  9. jenkins-infra-bot commented on Oct 20, 2016

    @jenkins-infra-bot
    Author
    maxzilla:
    • Original comment link
    • Raw content of original comment:

      jglick: What would it look like with the modifications you proposed when there's nothing to archive?

    jglick: What would it look like with the modifications you proposed when there's nothing to archive?

  10. jenkins-infra-bot commented on Oct 20, 2016

    @jenkins-infra-bot
    Author
    jglick:
    • Original comment link
    • Raw content of original comment:

      It would print a warning before failing, as already happens for freestyle builds.

    It would print a warning before failing, as already happens for freestyle builds.

  11. jenkins-infra-bot commented on Jan 9, 2017

    @jenkins-infra-bot
    Author
    harryjenkins:
    • Original comment link
    • Raw content of original comment:

      jglick: Would this patch mean that the archive stage in pipeline steps view would show as failed?

    jglick: Would this patch mean that the archive stage in pipeline steps view would show as failed?

  12. jenkins-infra-bot commented on Jan 29, 2017

    @jenkins-infra-bot
    Author
    ileitch:
    • Original comment link
    • Raw content of original comment:

      Would be great to have this resolved. This is was a huge time sink for me to track down.

    Would be great to have this resolved. This is was a huge time sink for me to track down.

  13. jenkins-infra-bot commented on Feb 2, 2017

    @jenkins-infra-bot
    Author
    roemer:
    • Original comment link
    • Raw content of original comment:

      Same for me. Almost half a day to figure out that this silently fails the build without any warning!

    Same for me. Almost half a day to figure out that this silently fails the build without any warning!

  14. jenkins-infra-bot commented on Feb 5, 2017

    @jenkins-infra-bot
    Author
    danielbeck:
    • Original comment link
    • Raw content of original comment:

      Notably (IIRC) freestyle jobs log when a step makes the build result worse. Looks like Pipeline does not?

    Notably (IIRC) freestyle jobs log when a step makes the build result worse. Looks like Pipeline does not?

  15. jenkins-infra-bot commented on Feb 8, 2017

    @jenkins-infra-bot
    Author
    crb:
    • Original comment link
    • Raw content of original comment:

      I would like to add that it looks to me that archiveArtifacts also (silently) fails when using absolute paths:

      def myfile1 = "foobar"
      sh "echo foobar > ${myfile1}"
      archiveArtifacts artifacts: "${myfile1}", fingerprint: true
      

      works correctly,

      def myfile1 = "${WORKSPACE}/foobar"
      sh "echo foobar > ${myfile1}"
      archiveArtifacts artifacts: "${myfile1}", fingerprint: true
      

      on the other hand does not.

    I would like to add that it looks to me that archiveArtifacts also (silently) fails when using absolute paths:

    def myfile1 = "foobar"
    sh "echo foobar > ${myfile1}"
    archiveArtifacts artifacts: "${myfile1}", fingerprint: true
    

    works correctly,

    def myfile1 = "${WORKSPACE}/foobar"
    sh "echo foobar > ${myfile1}"
    archiveArtifacts artifacts: "${myfile1}", fingerprint: true
    

    on the other hand does not.

  16. 5 remaining items

  17. jenkins-infra-bot commented on Jul 4, 2017

    @jenkins-infra-bot
    Author
    estyrke:
    • Original comment link
    • Raw content of original comment:

      abayer, as far as I can see, the step still shows with a green dot in "pipeline steps" view (and with a green check mark in BlueOcean). See JENKINS-45200 which I reported the other day.

      I get somewhere around 25 Mb of logs from my build, with multiple archiving steps, so even with the error message, finding out why my build failed was quite hard.

    abayer, as far as I can see, the step still shows with a green dot in "pipeline steps" view (and with a green check mark in BlueOcean). See JENKINS-45200 which I reported the other day.

    I get somewhere around 25 Mb of logs from my build, with multiple archiving steps, so even with the error message, finding out why my build failed was quite hard.

  18. jenkins-infra-bot commented on Jul 4, 2017

    @jenkins-infra-bot
    Author
    jglick:
    • Original comment link
    • Raw content of original comment:

      If you continue to have an issue using Jenkins 2.59 or later please file a separate issue (linked) with steps to reproduce from scratch.

    If you continue to have an issue using Jenkins 2.59 or later please file a separate issue (linked) with steps to reproduce from scratch.

  19. jenkins-infra-bot commented on Nov 25, 2018

    @jenkins-infra-bot
    Author
    ringerc:
    • Original comment link
    • Raw content of original comment:

      The comments here about "silently" failing the build make me think it'd be very good to capture the hudson.Abort exception and its stack. Then when the pipeline aborts, print

      "Pipeline aborted. (See stack)", with "(See stack)" as a ConsoleAnnotation that lets you view the stack that led to the abort.

      Even "Pipeline aborted in 'build' step at line '42'" would be a massive help though.

    The comments here about "silently" failing the build make me think it'd be very good to capture the hudson.Abort exception and its stack. Then when the pipeline aborts, print

    "Pipeline aborted. (See stack)", with "(See stack)" as a ConsoleAnnotation that lets you view the stack that led to the abort.

    Even "Pipeline aborted in 'build' step at line '42'" would be a massive help though.

  20. jenkins-infra-bot commented on Nov 27, 2018

    @jenkins-infra-bot
    Author
    jglick:
    • Original comment link
    • Raw content of original comment:

      ringerc as far as I know this issue is fixed, and when a Step fails with an AbortException, the log will display that message. That said, having an optional link in the (“classic”) UI to display the full stack trace from an AbortException (which is normally concealed) would be a neat enhancement for workflow-job-plugin.

    ringerc as far as I know this issue is fixed, and when a Step fails with an AbortException, the log will display that message. That said, having an optional link in the (“classic”) UI to display the full stack trace from an AbortException (which is normally concealed) would be a neat enhancement for workflow-job-plugin.

  21. jenkins-infra-bot commented on Nov 24, 2025

    @jenkins-infra-bot
    Author

    [Original is_duplicated_by from Jira: JENKINS-31931]

  22. jenkins-infra-bot commented on Nov 24, 2025

    @jenkins-infra-bot
    Author

    [Original is_duplicated_by from Jira: JENKINS-40538]

  23. jenkins-infra-bot commented on Nov 24, 2025

    @jenkins-infra-bot
    Author

    [Original is_duplicated_by from Jira: JENKINS-41249]

  24. removed
    bugFor changelog: Minor bug. Will be listed after features
    on Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions