Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-42478

Post block lacks access to node when Docker initialization fails

      Maybe this is true of agent any too (did not check), but saw that if you do something like

      pipeline {
        options {
          skipDefaultCheckout()
          // I think I had a timeout here too
        }
        agent {
          docker {
            image 'whatever'
          }
        }
        stages {
          stage('x') {
            steps {
              checkout scm
              sh '...'
            }
          }
        }
        post {
          failure {
            archiveArtifacts artifacts: '...', allowEmptyArchive: true
          }
        }
      }
      

      and the sh step fails, you get an error message complaining that archiveArtifacts must be run inside a node block.

          [JENKINS-42478] Post block lacks access to node when Docker initialization fails

          Andrew Bayer added a comment -

          Did the build fail, possibly before entering the docker container? post normally runs within the top-level agent, but if something goes wrong either before entering the agent or in the setup of the agent, post will still run but, not surprisingly, not inside the agent.

          Andrew Bayer added a comment - Did the build fail, possibly before entering the docker container? post normally runs within the top-level agent , but if something goes wrong either before entering the agent or in the setup of the agent , post will still run but, not surprisingly, not inside the agent .

          Jesse Glick added a comment -

          Ah, I missed that. Indeed docker pull failed. The post block could have run on the node—which did get allocated correctly—but not inside the container.

          So really we need two kinds of post failure blocks, depending on whether you assume you are running inside the agent or not.

          Jesse Glick added a comment - Ah, I missed that. Indeed docker pull failed. The post block could have run on the node—which did get allocated correctly—but not inside the container. So really we need two kinds of post failure blocks, depending on whether you assume you are running inside the agent or not.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          Jenkinsfile
          http://jenkins-ci.org/commit/plugin-pom/1a70fab444cf97dffd18bd5f11a81acfc0bf0f58
          Log:
          try-catch block was bogus. Trying to switch to Declarative, with JENKINS-42478 workaround.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: Jenkinsfile http://jenkins-ci.org/commit/plugin-pom/1a70fab444cf97dffd18bd5f11a81acfc0bf0f58 Log: try-catch block was bogus. Trying to switch to Declarative, with JENKINS-42478 workaround.

          Jesse Glick added a comment -

          vqrs notes a case where running build (without wait: false) inside a post block is undesirable as it blocks the executor needlessly.

          Jesse Glick added a comment - vqrs  notes a case where running build  (without wait: false ) inside a post block is undesirable as it blocks the executor needlessly.

          Jesse Glick added a comment -

          Or how about this:

          • If the node is allocated successfully, then any steps in a post block which require node context (by inspecting their descriptors) are run, then the executor is released, then any remaining steps are run.
          • Otherwise, any steps in a post block requiring node context are ignored, and the rest are run.

          Jesse Glick added a comment - Or how about this: If the node is allocated successfully, then any steps in a post block which require node context (by inspecting their descriptors) are run, then the executor is released, then any remaining steps are run. Otherwise, any steps in a post block requiring node context are ignored, and the rest are run.

            Unassigned Unassigned
            jglick Jesse Glick
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: