Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-49946

input step cannot access environment blocks

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      The input step in declarative pipeline (JENKINS-48379) cannot access the environment blocks. Thus, dynamic data (e.g. version number) cannot be used in the input dialog. Also defining options in the input and checking the result requires redundant values, because they cannot be reused.

      • Access to $JOB_NAME and ${env.JOB_NAME} is working.
      • Access to $myVar is not working. It leads to a "no such property" exception. It doesn't matter if the variable is declared in the global or stage-local environment block.
      • Access to ${env.myVar} is not working. The value is null. It doesn't matter if the variable is declared in the global or stage-local environment block.

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            Part of this another ordering issue, like JENKINS-49947: either we can have input results available when evaluating its stage's environment or the other way around, but not both. But top-level environment variables should be available to input - that's a bug. Can you provide a simple Jenkinsfile reproducing this? Thanks!

            Show
            abayer Andrew Bayer added a comment - Part of this another ordering issue, like JENKINS-49947 : either we can have input results available when evaluating its stage's environment or the other way around, but not both. But top-level environment variables should be available to input - that's a bug. Can you provide a simple Jenkinsfile reproducing this? Thanks!
            Hide
            abayer Andrew Bayer added a comment -

            As I commented above, this is a deliberate decision on ordering - we have chosen to have input process before environment for a stage, because you may want to have the environment reference something in the workspace or something submitted from input. If you need to define a single stage environment variable and reference it in that stage's input, you can wrap the stage inside a parent stage where you define the environment variable, like this:

            stage("parent") {
              environment {
                FOO = "bar"
              }
              stages {
                stage("child") {
                  input {
                    message "Continue with ${FOO}?"
                  }
                  ...
                }
              }
            }
            
            Show
            abayer Andrew Bayer added a comment - As I commented above, this is a deliberate decision on ordering - we have chosen to have input process before environment for a stage , because you may want to have the environment reference something in the workspace or something submitted from input . If you need to define a single stage environment variable and reference it in that stage 's input , you can wrap the stage inside a parent stage where you define the environment variable, like this: stage( "parent" ) { environment { FOO = "bar" } stages { stage( "child" ) { input { message "Continue with ${FOO}?" } ... } } }
            Hide
            mrmarc Marc Smith added a comment -

            Hi Andrew, here is an example pipeline that does NOT work.
            Please note the environment block is global so it should be available.

            pipeline {
                agent any
                environment {
                    SEM_VER = "1.1.0"
                }
            
                stages {
                    stage('Approval') {
                        input {
                            message "✅ All Unit tests passed, Deploy ${SEM_VER}?"
                            id 'Approve & Deploy Build'
                        }
                        steps {
                            echo 'Deploying the build...'
                        }
                    }
                }
            }
            

            I get

            groovy.lang.MissingPropertyException: No such property: SEM_VER for class: groovy.lang.Binding
            	at groovy.lang.Binding.getVariable(Binding.java:63)
            	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:264)
            	at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
            	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
            	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
            	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
            	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
            	at WorkflowScript.run(WorkflowScript:11)
            	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:59)
            	at WorkflowScript.run(WorkflowScript:1)
            	at ___cps.transform___(Native Method)
            	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
            	at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
            	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
            	at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            	at java.lang.reflect.Method.invoke(Method.java:498)
            	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:83)
            	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
            	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
            	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
            	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
            	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
            	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
            	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:182)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
            	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
            	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
            	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
            	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
            	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
            	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            	at java.lang.Thread.run(Thread.java:748)
            Finished: FAILURE
            

             

            Show
            mrmarc Marc Smith added a comment - Hi Andrew, here is an example pipeline that does NOT work. Please note the environment block is global so it should be available. pipeline { agent any environment { SEM_VER = "1.1.0" } stages { stage( 'Approval' ) { input { message "✅ All Unit tests passed, Deploy ${SEM_VER}?" id 'Approve & Deploy Build' } steps { echo 'Deploying the build...' } } } } I get groovy.lang.MissingPropertyException: No such property: SEM_VER for class: groovy.lang.Binding at groovy.lang.Binding.getVariable(Binding.java:63) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:264) at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288) at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292) at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29) at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20) at WorkflowScript.run(WorkflowScript:11) at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/ var /jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:59) at WorkflowScript.run(WorkflowScript:1) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74) at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30) at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66) at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) 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:83) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163) at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122) at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:182) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang. Thread .run( Thread .java:748) Finished: FAILURE  
            Hide
            darenjsmith Daren Smith added a comment -

            I'm surprised this issue has been closed. I cannot determine a way to display any dynamic values in the input directive for declarative pipeline. I really like that this has been added, but the inability to use dynamic values in it really limits the usefulness. As other user have stated:

            1. A globally scoped environment variable results in null when used
            2. A defined groovy string that is overridden in a subsequent stage results in the originally set value
            3. The recommendation for a nested stage results in an error because only steps or parallel are allowed keyword in a stage. Changing to stages to parallel allows it to work, but still results in a null value for the env var just as the globally scoped env var did.

            For now it appears we are stuck utilizing another stage without an agent to get the desired result, but that is not very clean and defeats the purpose that the declarative input directive was meant to solve.

            Show
            darenjsmith Daren Smith added a comment - I'm surprised this issue has been closed. I cannot determine a way to display any dynamic values in the input directive for declarative pipeline. I really like that this has been added, but the inability to use dynamic values in it really limits the usefulness. As other user have stated: A globally scoped environment variable results in null when used A defined groovy string that is overridden in a subsequent stage results in the originally set value The recommendation for a nested stage results in an error because only steps or parallel are allowed keyword in a stage. Changing to stages to parallel allows it to work, but still results in a null value for the env var just as the globally scoped env var did. For now it appears we are stuck utilizing another stage without an agent to get the desired result, but that is not very clean and defeats the purpose that the declarative input directive was meant to solve.
            Hide
            tamerlaha ipleten added a comment -

            Could this be re-opened and addressed properly, please? 

            Show
            tamerlaha ipleten added a comment - Could this be re-opened and addressed properly, please? 
            Hide
            bwolin Ben Wolin added a comment -

            I have this problem also. Would really like to have a way to use the environment in inputs

             

            Show
            bwolin Ben Wolin added a comment - I have this problem also. Would really like to have a way to use the environment in inputs  
            Show
            enummela Erik Nummela added a comment - See  https://issues.jenkins-ci.org/browse/JENKINS-49946?focusedCommentId=355332&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-355332
            Hide
            enummela Erik Nummela added a comment - - edited

            This simple pipeline results in values of null where the environment variables should be

             pipeline {
                agent any
                environment {
                    PROJECT = "my-project"
                }
            
                stages {
                    stage('Approval') {
                        input {
                          message "Do you want to release a new version of ${env.PROJECT} to AWS (revision: ${env.GIT_COMMIT})?"
                          ok "Yes, proceed"
                        }
                        steps {
                          echo "Starting to deploy ${env.PROJECT}."
                        }
                    }
                }
            }

            Which produces the following output on invoking the pipeline

            Do you want to release a new version of null to AWS (revision: null)?
            Show
            enummela Erik Nummela added a comment - - edited This simple pipeline results in values of  null where the environment variables should be pipeline { agent any environment { PROJECT = "my-project" } stages { stage( 'Approval' ) { input { message "Do you want to release a new version of ${env.PROJECT} to AWS (revision: ${env.GIT_COMMIT})?" ok "Yes, proceed" } steps { echo "Starting to deploy ${env.PROJECT}." } } } } Which produces the following output on invoking the pipeline Do you want to release a new version of null to AWS (revision: null )?

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                aklemp Andreas Klemp
              • Votes:
                1 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated: