[JIRA] (JENKINS-59990) values set by environment directive are not captured for RunWrapper.getBuildVariables

4 views
Skip to first unread message

savepointsam@gmail.com (JIRA)

unread,
Oct 30, 2019, 4:05:01 PM10/30/19
to jenkinsc...@googlegroups.com
Sam Horton commented on Bug JENKINS-59990
 
Re: values set by environment directive are not captured for RunWrapper.getBuildVariables

Slightly related to JENKINS-36528.

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

savepointsam@gmail.com (JIRA)

unread,
Oct 30, 2019, 4:05:03 PM10/30/19
to jenkinsc...@googlegroups.com
Sam Horton created an issue
 
Jenkins / Bug JENKINS-59990
Issue Type: Bug Bug
Assignee: Unassigned
Components: workflow-support-plugin
Created: 2019-10-30 20:04
Environment: jenkins-2.190.2-1.1.noarch, workflow-support:3.3
Labels: pipeline plugin
Priority: Minor Minor
Reporter: Sam Horton

When using the environment directive in a declarative pipeline, the environment variables that are set are not captured and exposed via the RunWrapper.getBuildVariables method.

For example, the following pipeline will yield an empty Map after execution.

Jenkinsfile

pipeline {
    environment {
        MY_ENVVAR = "example"
    }

    stages {
        stage("run job") {
            steps {
                sh 'printenv | sort'
            }
        }
    }
}

Result

 

[:]

 

 

However, if we set this environment variable via the script directive it is captured and made available in the response of RunWrapper.getBuildVariables.

Jenkinsfile

pipeline {
   stages {
       stage("run job") {
           steps {
               script {
                   env.MY_ENVVAR = "example"
               }

               sh 'printenv | sort'
           }
       }
   }
}

 

Result

 

[MY_ENVVAR:example]

 

I would expect that ALL custom set environment variables should be retrieved.

 

 

savepointsam@gmail.com (JIRA)

unread,
Oct 30, 2019, 4:07:03 PM10/30/19
to jenkinsc...@googlegroups.com
Sam Horton updated an issue
Change By: Sam Horton
When using the environment directive in a declarative pipeline, the environment variables that are set are not captured and exposed via the RunWrapper.getBuildVariables method.

For example, the following pipeline will yield an empty Map after execution.

*Jenkinsfile*
{code:java}

pipeline {
    environment {
        MY_ENVVAR = "example"
    }

    stages {
        stage("run job") {
            steps {
                sh 'printenv | sort'
            }
        }
    }
}{code}
*Result*

 
{code:java}
[:]
{code}
 


 

However, if we set this environment variable via the script directive it is captured and made available in the response of RunWrapper.getBuildVariables.

*Jenkinsfile*
{code:java}

pipeline {
   stages {
       stage("run job") {
           steps {
               script {
                   env.MY_ENVVAR = "example"
               }

               sh 'printenv | sort'
           }
       }
   }
}
{code}
 

*Result*

 
{code:java}
[MY_ENVVAR:example]{code}

 

I would expect that ALL custom set environment variables should be retrieved.
Reply all
Reply to author
Forward
0 new messages