Get the root directory of node in Pipeline

1.069 visualizzazioni
Passa al primo messaggio da leggere

Kristian

da leggere,
9 gen 2017, 11:45:5309/01/17
a jenkins...@googlegroups.com
Hi,

do someone knows how to get the root directory of a node in a Pipeline script?

Slide

da leggere,
9 gen 2017, 11:54:1509/01/17
a jenkins...@googlegroups.com
You can use pwd, to get it.

node() { 
   ROOT = pwd()
}

On Mon, Jan 9, 2017 at 9:45 AM Kristian <kristian...@gmail.com> wrote:
Hi,

do someone knows how to get the root directory of a node in a Pipeline script?

--
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/CAO5HUhMvCZXGLe91bb4W%3DpHGH470C2QbVF5CX70XdeL0aYm5_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Kristian

da leggere,
9 gen 2017, 12:01:5909/01/17
a jenkins...@googlegroups.com
This gives me the workspace of the job. But I want the root directory
which I set when I create a new slave node in Jenkins.

So, as an example, I create a new slave node. The root directory i am
setting there is /home/jenkins.
Currently, when I run a job, I get "/home/jenkins/workspace/Some Job
Name" when running pwd(). But I want only this "/home/jenkins" stuff.
> https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVfJ0UjVfPnQhq8rTsj6Sde9uCUKOopQzJfLRRegLiWE1Q%40mail.gmail.com.

Indra Gunawan (ingunawa)

da leggere,
9 gen 2017, 18:50:3009/01/17
a jenkins...@googlegroups.com
How about this :


import jenkins.model.*

node () {
def nodeName = ${env.NODE_NAME}
def nodeRootPath = nodeRootDir(nodeName)
...

}

@NonCPS
def nodeRootDir(nodeName) {
for (node in Jenkins.instance.nodes) {
if ( !nodeName.equals('master') && node.name.equals(nodeName) ) {
return node.getRootPath()
break
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO5HUhOBwpNj0aEoB3G_sWYaZAExoakgmSX9udSx7CvQQeCYdw%40mail.gmail.com.

Kristian

da leggere,
10 gen 2017, 05:03:5610/01/17
a jenkins...@googlegroups.com
I had to change the nodeRootDir() a little bit, but this way works for me:

@NonCPS
def nodeRootDir(nodeName) {
for (node in Jenkins.instance.nodes) {
if (!nodeName.equals('master') &&
node.name.compareTo(nodeName) == 0 ) {
return node.getRootPath()
break
}
}
}


Thank you for your help!
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3E417B6C-4745-4E56-BF49-9DA1E8579708%40cisco.com.
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi