• Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • scriptler-plugin
    • None
    • Scriptler v2.9 Jenkins v1.596.2

      I have a script executed through the scriptler plugin and I would like to use in the script job environment variables such as BUILD_URL. At the beginnig of the script I read the environment variables with

      def env = System.getenv() //also get the environment
      //then print to confirm
      env.each{
        println "${it.key} :${it.value}" 
      }
      

      Independent of whether I check the 'Propagate Job params to script' checkbox the parameters are the same and only related to the OS. I do not see any of the JOB related environement variables. See example screen shot attached

          [JENKINS-37485] Propagate Job params to script does nothing

          I think this is just a misunderstanding - the build variables will not be propagated as environment variables, but as script variables...

          So in your case, just access the parameter as a variable in your script, e.g. like this:

          println BUILD_URL

          Dominik Bartholdi added a comment - I think this is just a misunderstanding - the build variables will not be propagated as environment variables, but as script variables... So in your case, just access the parameter as a variable in your script, e.g. like this: println BUILD_URL

          Thank you for the clarification domi ! From what I can tell this allows ALL build parameters to be in the script binding, but unfortunately there is a large number of important parameters that are still missing.Specifically, I would like to use variables such as JOB_NAME, BUILD_URL, BUILD_TAG and the like. These are all build specific and allow for the dynamic behavior of the script. However, they are not defined as build parameters and so they are not in the script binding. However, they can be passed to the script explicitly by adding a new script parameter like vJOB_NAME=$JOB_NAME and then using vJOB_NAME variable in the script.

          Ioannis Moutsatsos added a comment - Thank you for the clarification  domi ! From what I can tell this allows ALL build parameters to be in the script binding, but unfortunately there is a large number of important parameters that are still missing.Specifically, I would like to use variables such as JOB_NAME, BUILD_URL, BUILD_TAG and the like. These are all build specific and allow for the dynamic behavior of the script. However, they are not defined as build parameters and so they are not in the script binding. However, they can be passed to the script explicitly by adding a new script parameter like vJOB_NAME=$JOB_NAME and then using vJOB_NAME variable in the script.

          imod I have tried the suggestion you provided and instead I get an error:
          groovy.lang.MissingPropertyException: No such property: BUILD_URL for class

          Ioannis Moutsatsos added a comment - imod I have tried the suggestion you provided and instead I get an error: groovy.lang.MissingPropertyException: No such property: BUILD_URL for class

          ioannis sorry, this should work:

          println ${env.BUILD_URL}

          Dominik Bartholdi added a comment - ioannis sorry, this should work: println ${env.BUILD_URL}

          imod Thanks for the guidance. Unfortunately I'm still getting errors trying to access environment variables from the scriptlet using this approach. For example:

          Execution of script [export_metadata_query.groovy] failed - groovy.lang.MissingPropertyException: No such property: env for class: Script1org.jenkinsci.plugins.scriptler.util.GroovyScript$ScriptlerExecutionException: groovy.lang.MissingPropertyException: No such property: env for class: Script1
          	at org.jenkinsci.plugins.scriptler.util.GroovyScript.call(GroovyScript.java:131)
          	at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
          

          Ioannis Moutsatsos added a comment - imod Thanks for the guidance. Unfortunately I'm still getting errors trying to access environment variables from the scriptlet using this approach. For example: Execution of script [export_metadata_query.groovy] failed - groovy.lang.MissingPropertyException: No such property: env for class: Script1org.jenkinsci.plugins.scriptler.util.GroovyScript$ScriptlerExecutionException: groovy.lang.MissingPropertyException: No such property: env for class: Script1 at org.jenkinsci.plugins.scriptler.util.GroovyScript.call(GroovyScript.java:131) at hudson.remoting.LocalChannel.call(LocalChannel.java:45)

            domi Dominik Bartholdi
            ioannis Ioannis Moutsatsos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: