Jenkins pipeline build stuck forever if node doesn't exist

376 views
Skip to first unread message

Ali Ok

unread,
Jun 8, 2017, 11:49:11 AM6/8/17
to jenkins...@googlegroups.com

I have a Jenkins pipeline like:

node("slave1"){
  echo "Building very very complicated things"
}

If the node "slave1" does not exist in my Jenkins setup, the build is stuck forever.

I know I could use timeout keyword and wrap the node command. However, this is not good since timeout can happen because of inexistent node or long-taking build. That's not really a solution.

Any calls that I can do to check if a node exists or not?

I understand I can use timeout and wrap something like this : node("slave1"){echo "Hello"} . That way I can test if node exists. However, this actually makes a connection to the node (in my case, spawns a container in OpenShift/Kubernetes and wastes it immediately)

I use Jenkins 2.32.2 and pipeline plugin version 2.1.

Łukasz Zachulski

unread,
Jun 10, 2017, 6:16:24 PM6/10/17
to Jenkins Users
Two solutions have came to my mind:

First method is based on an idea of making REST call from node("master") { sh "curl ..." } to confirm if Jenkins instance contains node.

Second method is only applicable if your Pipeline script is "trusted" and it's not run inside "a sandbox". Then you could make a Java/Groovy call directly targeting Jenkins instance using API.

Cheers,
Reply all
Reply to author
Forward
0 new messages