deadlock when run two pipelines parallel in jenkins

The easiest workaround to this is to just bump the number of executors by one, ensuring you always have one more executor than you do parent jobs.

This way there will always be either one executor free or one child job running which will complete and free the executor.

You can set executors in Manage Jenkins > Nodes > (node name) > Configure > # of executors

This isn't a full solution though, as you'd need to do it every time you add a job.


Struggled with the same issue.

You didn't give your Jenkinsfile but if your pipeline requires 1 executor node to run the pipeline and 1 additional to execute the job it is probably that you set an agent at pipeline level and also at stage level like

pipeline {
  agent any

  stage('Build') {
    agent {
      label 'my label'
    }

    steps {
      ...
    }
  }

  post {
    always {
      ...
    }
  }
}

as I did. Of course your specific agent setting can be very different, but the agent is set at 2 levels. The reason I had to specify a pipeline level agent in addition to the stage was because otherwise my post step wouldn't run.

If your pipeline requires specific agent settings (labels, docker images, ...) at stage level, it is best practice to set agent none at pipeline level:

pipeline {
  agent none

  stage('Build') {
    agent {
      label 'my label'
    }

    steps {
      ...
    }
  }
}

This way only 1 executor node is needed thus preventing the deadlock.

If like me you need a post step you can run it like

pipeline {
  agent none

  stage('Build') {
    agent {
      label 'my other label'
    }

    steps {
      ...
    }
  }

  post {
    always {
      node('label') {
        ...
      }
    }
  }
}

to provide it with a node. The label is mandatory, haven't found a way to run it on any node. Adding the node{} bloc allows the post block to run with agent none set at pipeline level.

This worked for me and might be a solution for the OP. Not enough information was given in the OP to know the specific configuration of the pipeline.