Evaluation of $WORKSPACE seems wrong

24 views
Skip to first unread message

Rasmus Uth Pedersen

unread,
Mar 20, 2018, 10:29:10 AM3/20/18
to jenkins...@googlegroups.com

Hi,

 

Given the following Jenkinsfile I would expect two different workspaces to be printed but that is not the case. Am I doing something wrong?

 

def getWorkspace() {

    path = "${WORKSPACE}"

    sleep 1

    return path

}

 

def build_steps = [:]

 

build_steps['first'] = {

    node {

        println getWorkspace()

    }

}

 

build_steps['second'] = {

    node {

        println getWorkspace()

    }

}

stage ('test') {

    parallel build_steps

}

 

Console:

 

[Pipeline] stage

[Pipeline] { (test)

[Pipeline] parallel

[Pipeline] [first] { (Branch: first)

[Pipeline] [second] { (Branch: second)

[Pipeline] [first] node

[first] Running on agent1 in /home/jenkins/workspace/test

[Pipeline] [second] node

[Pipeline] [first] {

[second] Running on agent1 in /home/jenkins/workspace/test@2

[Pipeline] [second] {

[Pipeline] [first] sleep

[first] Sleeping for 1 sec

[Pipeline] [second] sleep

[second] Sleeping for 1 sec

[Pipeline] [first] echo

[first] /home/jenkins/workspace/test@2

[Pipeline] [first] }

[Pipeline] [first] // node

[Pipeline] [first] }

[Pipeline] [second] echo

[second] /home/jenkins/workspace/test@2

[Pipeline] [second] }

[Pipeline] [second] // node

[Pipeline] [second] }

[Pipeline] // parallel

[Pipeline] }

[Pipeline] // stage

[Pipeline] End of Pipeline

 

Best regards

Rasmus

Björn Rohlén

unread,
Mar 20, 2018, 12:33:44 PM3/20/18
to Jenkins Users
Hello.

Seems correct to me -- you are executing on the same node, there is no reason for it to be different within the same job. If you have multiple nodes you will have to stash / unstash to bring any files with you from previous step you have not published to an artifact repository like nexus or artifactory.

Regards,
-Björn

Rasmus Uth Pedersen

unread,
Mar 21, 2018, 1:11:35 PM3/21/18
to jenkins...@googlegroups.com

Ok, I know what I did wrong now.

This:

path = "${WORKSPACE}"

 

Should be changed to:

def path = "${WORKSPACE}"

 

without def, path will be a variable with script-scope making getWorkspace() return the workspace of the last caller.

Making path a local variable fixes the problem.

 

Best regards

Rasmus

 

Reply all
Reply to author
Forward
0 new messages