Re: workflow plugin -- dynamically select specifc slave nodes in for loop

169 views
Skip to first unread message

Baptiste Mathus

unread,
Apr 24, 2015, 12:38:25 AM4/24/15
to jenkins...@googlegroups.com
What do you mean it fails? You mean it only does it on the first node? Might be known issue, IIRC. There's been report in the past that someList.forEach() would only process the fist element. That sounds related.

2015-04-10 18:34 GMT+02:00 Anshu Arya <an...@anshuarya.com>:
I want to use a list of nodes to launch a command on specific nodes, so I tried this:

for (node_name in all_nodes) {
    node
(node_name) {
        echo
'My name is ' + node_name
   
}
}

This works for the first node in "all_nodes" but then fails after that.  Is there a better way to do this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3895e5f1-866e-4c6b-aef8-8b4a7f942347%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !

Anshu Arya

unread,
Apr 27, 2015, 11:06:12 PM4/27/15
to jenkins...@googlegroups.com, bma...@batmat.net
Yes, it executes on the first node, but the remaining nodes do not respond and the job fails at that point.

Anshu Arya

unread,
Apr 27, 2015, 11:18:09 PM4/27/15
to jenkins...@googlegroups.com, bma...@batmat.net
More info:

echo TEST_MACHINES

def all_nodes = TEST_MACHINE.split(',')

for (node_name in all_nodes) {
    echo
'Plan to run on ' + node_name
}


for (node_name in all_nodes) {
    node
(node_name) {
        echo
'My name is ' + node_name
   
}
}

Results in:

Running: Print Message
A10-4600M,A10-5700,A10-6800K,A10-7850B
Running: Print Message
Plan to run on A10-4600M
Running: Print Message
Plan to run on A10-5700
Running: Print Message
Plan to run on A10-6800K
Running: Print Message
Plan to run on A10-7850B
Running: Allocate node : Start
Running on A10-4600M in C:\Jenkins_work\workspace\Windows_Application_Workflow@2
Running: End of Workflow
java.io.NotSerializableException: java.util.AbstractList$Itr
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:343)
at java.util.HashMap.writeObject(HashMap.java:1129)
at sun.reflect.GeneratedMethodAccessor724.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)
at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)
at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:133)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:341)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:325)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:300)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:71)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:177)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:175)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: an exception which occurred:
in field itr
in field target
in field continue_
in field parent
in field capture
in field def
in field closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@45617a6b
Finished: FAILURE

Jesse Glick

unread,
Jun 16, 2015, 3:38:13 PM6/16/15
to jenkins...@googlegroups.com, bma...@batmat.net
On Monday, April 27, 2015 at 11:18:09 PM UTC-4, Anshu Arya wrote:
java.io.NotSerializableException: java.util.AbstractList$Itr

Owen B. Mehegan

unread,
Jul 13, 2015, 8:02:01 PM7/13/15
to jenkins...@googlegroups.com, bma...@batmat.net
I'm trying to accomplish basically the same thing - I have identical steps that I want to run on >1 slave, in parallel. Is there any other succinct way to write this? Right now I am duplicating everything for each slave, which should offend anyone's sense of programming decency :)

Being able to write:
node('linux_slave', 'windows_slave') {
  // some steps to run in parallel on both slaves
}

would be fantastic.

Anshu Arya

unread,
Jul 13, 2015, 8:19:57 PM7/13/15
to jenkins...@googlegroups.com, bma...@batmat.net
The workaround right now is to just use normal C-style loops. For example if you want to do stuff in parallel:

def parTask = [:]

for(int i = 0; i < all_nodes.size(); i++) {

   def node_name = all_nodes[i]
   parTask
[node_name] = { /* stuff to do in parallel */ }

}
parallel parTask

Anshu Arya

unread,
Jul 13, 2015, 8:24:18 PM7/13/15
to jenkins...@googlegroups.com, bma...@batmat.net
Whoops, this is the code:
def parTask = [:]

for(int i = 0; i < all_nodes.size(); i++) {
   
def node_name = all_nodes[i]
   parTask
[node_name] = {

     node
(node_name) {/* stuff to do in parallel across selected nodes */ }
   
}
}
parallel parTask

Owen B. Mehegan

unread,
Jul 14, 2015, 6:52:39 PM7/14/15
to jenkins...@googlegroups.com, bma...@batmat.net
Oh, thanks! I had seen that example code before but misunderstood what it was doing. Now it makes sense, and I have it working.
Reply all
Reply to author
Forward
0 new messages