Jenkins Pipeline/Workflow node name as variable

3,085 views
Skip to first unread message

Frank Hask

unread,
Mar 17, 2016, 8:23:22 AM3/17/16
to Jenkins Users
Hi all, i am building pipeline on my project that uses 5 DB servers.

So based on build variable i want to set node name. Like this..

env.NODE = 'blabla'


node
('${NODE}') {
 
//some code
}

but each time i get error - There are no nodes with the label ‘${NODE}’

Thanks for help in advance...

Vincent Latombe

unread,
Mar 17, 2016, 9:28:09 AM3/17/16
to Jenkins Users
Use double quotes if you want expressions resolved.

Vincent

--
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/bf6fe502-84b4-401a-ae57-e003e8e37f01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Baptiste Mathus

unread,
Mar 18, 2016, 3:58:46 AM3/18/16
to jenkins...@googlegroups.com

Inline

Le 17 mars 2016 1:23 PM, "Frank Hask" <nikoli...@gmail.com> a écrit :
>
> Hi all, i am building pipeline on my project that uses 5 DB servers.
>
> So based on build variable i want to set node name. Like this..
>
> env.NODE = 'blabla'
>
>
> node('${NODE}') {
>   //some code
> }

Why don't you just do:
def nodeLabel = 'blabla'
node(nodeLabel) {
...
}

?

Here you seem to want to define an environment variable. Not a pipeline (groovy) variable. Is this intended?

>
> but each time i get error - There are no nodes with the label ‘${NODE}’
>
> Thanks for help in advance...
>

Frank Hask

unread,
Mar 21, 2016, 4:26:15 AM3/21/16
to Jenkins Users, m...@batmat.net
Baptiste thank you for reminding me to try out this method. I will give it a try..

Frank Hask

unread,
Mar 21, 2016, 5:48:58 AM3/21/16
to Jenkins Users, m...@batmat.net
@Baptiste

When i use this method i am also getting errors..

def NODE = 'bla bla'


node
(NODE){
   
//some code
}


I get the following stacktrace

groovy.lang.MissingPropertyException: No such property: ENVIRONMNET for class: WorkflowScript
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:454)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:25)
	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:17)
	at WorkflowScript.run(WorkflowScript:56)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:62)
	at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:54)
	at sun.reflect.GeneratedMethodAccessor805.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
	at com.cloudbees.groovy.cps.Next.step(Next.java:58)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:277)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:77)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:186)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:184)
	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)
Finished: FAILURE

Frank Hask

unread,
Mar 21, 2016, 5:50:40 AM3/21/16
to Jenkins Users


Dana četvrtak, 17. ožujka 2016. u 13:23:22 UTC+1, korisnik Frank Hask napisao je:
Hi all, i am building pipeline on my project that uses 5 DB servers.

So based on build parameter i want to set node name. Like this..

env.NODE = ${blabla}



node
('${NODE}') {
 
//some code
}

Eric Pyle

unread,
Mar 21, 2016, 10:14:41 AM3/21/16
to jenkins...@googlegroups.com
It looks like the word 'ENVIRONMENT' is misspelled in the stacktrace - not sure if this is the problem. The stacktrace indicates the error occurs on line 56 of your script, so it would help to know what is on that line.

Eric
--
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.
Reply all
Reply to author
Forward
0 new messages