[JIRA] (JENKINS-59871) env hashmap randomly mixes values of two parallel nodes

4 views
Skip to first unread message

alexander.samoylov@gmail.com (JIRA)

unread,
Oct 21, 2019, 10:37:03 AM10/21/19
to jenkinsc...@googlegroups.com
Alexander Samoylov created an issue
 
Jenkins / Bug JENKINS-59871
env hashmap randomly mixes values of two parallel nodes
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline
Created: 2019-10-21 14:36
Environment:
Labels: pipeline pipeline-environment
Priority: Major Major
Reporter: Alexander Samoylov

Please, look at this simple pipeline script:

def build(label) {
    // Set env globally (for all stages) on the current node
    env.MYENVVAR = env.WORKSPACE

    // Printout outside of stage
    print('WORKSPACE 0=' + env.WORKSPACE)
    print('MYENVVAR 0=' + env.MYENVVAR)

    stage ('Stage 1' + label) { // Printout in a stage
        print('WORKSPACE 1=' + env.WORKSPACE)
        print('MYENVVAR 1=' + env.MYENVVAR)
    }
}

// Main
parallel(
    'Unix' : {
        node ('build-linux') {
            build('Unix')
        }
    },
    'Windows' : {
        node ('build-win') {
            build('Windows')
        }
    }
)

This results to this output:

Running on build-linux in /home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
Running on build-win in c:\build\jenkins\pipeline_bug_parallel_env_mixed_up

[Unix] WORKSPACE 0=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
[Unix] MYENVVAR 0=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
[Windows] WORKSPACE 0=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
[Windows] MYENVVAR 0=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up

[Unix] WORKSPACE 1=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
*[Unix] MYENVVAR 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up* // BUG !!

[Windows] WORKSPACE 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
[Windows] MYENVVAR 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up

So the bug is that the env.MYENVVAR inside the [Unix] parallel branch on Unix node somehow takes value of the [Windows] parallel branch.
Expected result: env.MYENVVAR = env.WORKSPACE before all stages should have assigned env.MYENVVAR for all further stages, because it was done outside the stage, that is globally for the node.

There is a workaround. If I change the pipeline script by adding withEnv{} this way it works:

def build(label) {

    withEnv([ "MYENVVAR=" + env.WORKSPACE ]) { // WORKAROUND
    
        // Global
        //env.MYENVVAR = env.WORKSPACE
        print('WORKSPACE 0=' + env.WORKSPACE)
        print('MYENVVAR 0=' + env.MYENVVAR)

        stage ('Stage 1' + label) {
            print('WORKSPACE 1=' + env.WORKSPACE)
            print('MYENVVAR 1=' + env.MYENVVAR)
        }
    }
}

I don't know if my example is supposed to be supported, but if not then please fix it so that the null value is assigned. If the variable in one node {} takes value from another parallel node {} in a random way that seems to be really wrong.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

alexander.samoylov@gmail.com (JIRA)

unread,
Oct 21, 2019, 10:50:03 AM10/21/19
to jenkinsc...@googlegroups.com
Alexander Samoylov updated an issue
Change By: Alexander Samoylov
Please, look at this simple pipeline script:

{code:java}

def build(label) {
    // Set env globally (for all stages) on the current node
    env.MYENVVAR = env.WORKSPACE

    // Printout outside of stage
    print('WORKSPACE 0=' + env.WORKSPACE)
    print('MYENVVAR 0=' + env.MYENVVAR)

    stage ('Stage 1' + label) { // Printout in a stage
        print('WORKSPACE 1=' + env.WORKSPACE)
        print('MYENVVAR 1=' + env.MYENVVAR)
    }
}

// Main
parallel(
    'Unix' : {
        node ('build-linux') {
            build('Unix')
        }
    },
    'Windows' : {
        node ('build-win') {
            build('Windows')
        }
    }
)
{code}


This results to this output:
{code:java}

Running on build-linux in /home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
Running on build-win in c:\build\jenkins\pipeline_bug_parallel_env_mixed_up

[Unix] WORKSPACE 0=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
[Unix] MYENVVAR 0=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
[Windows] WORKSPACE 0=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
[Windows] MYENVVAR 0=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up

[Unix] WORKSPACE 1=/home/build/jenkins/workspace/pipeline_bug_parallel_env_mixed_up
*[Unix] MYENVVAR 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up* // BUG !!

[Windows] WORKSPACE 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
[Windows] MYENVVAR 1=c:\build\jenkins\pipeline_bug_parallel_env_mixed_up
{code}


So the bug is that the env.MYENVVAR inside the [Unix] parallel branch on Unix node somehow takes value of the [Windows] parallel branch.
Expected result: env.MYENVVAR = env.WORKSPACE before all stages should have assigned env.MYENVVAR for all further stages, because it was done outside the stage, that is globally for the node.

There is a workaround. If I change the pipeline script by adding withEnv{} this way it works:
{code:java}

def build(label) {

    withEnv([ "MYENVVAR=" + env.WORKSPACE ]) { // WORKAROUND
    
        // Global
        //env.MYENVVAR = env.WORKSPACE
        print('WORKSPACE 0=' + env.WORKSPACE)
        print('MYENVVAR 0=' + env.MYENVVAR)

        stage ('Stage 1' + label) {
            print('WORKSPACE 1=' + env.WORKSPACE)
            print('MYENVVAR 1=' + env.MYENVVAR)
        }
    }
}
{code}


I don't know if my example is supposed to be supported, but if not then please fix it so that the null value is assigned. If the variable in one node {}  takes value from another parallel node {} in a random way that seems to be really wrong.
Reply all
Reply to author
Forward
0 new messages