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

build parameter availability in DSL from pipelines

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • job-dsl-plugin
    • None
    • Jenkins 2.10
      JOB DSL 1.48

      I am trying to execute a grrovy DSL script as part of a pipeline. The basic structure is as follows

              step([
                  $class: 'ExecuteDslScripts',
                  scriptLocation: [targets: ['myseed.groovy'].join('\n')],
              ])
      

      The pipeline job contains a string parameter named as gitProject. Trying to access it's value by using "${gitProject}" from within the groovy DSL results in an error that says gitProject is not defined. Trying to wrap the step as follows doesn't help either

          withEnv(["gitProject=$gitProject"]) {
              sh 'set'
              step([
                  $class: 'ExecuteDslScripts',
                  scriptLocation: [targets: ['myseed.groovy'].join('\n')],
              ])
          }
      

      My guess is that the withEnv approach would not work as job DSLs do not have access to all environment variables; only whitelisted ones and build parameters make it. So I guess some change needs to be done to the plugin to ensure that it is able to access build parameters from within pipelines as well

          [JENKINS-36679] build parameter availability in DSL from pipelines

          Same issue on JOB DSL 1.50.

          Alexander Tolstikov added a comment - Same issue on JOB DSL 1.50.

          I debugged this. The environment variables are not returned from Run.getEnvironment() by the instance of hudson.model.Run that is passed into SimpleBuildStep when running in a Pipeline job. I'm not sure if this is a bug or by design. I added the core and pipeline components because this is IMHO not something that can be fixed in Job DSL. At least not without using Pipeline specific API which I would like to avoid.

          Daniel Spilker added a comment - I debugged this. The environment variables are not returned from Run.getEnvironment() by the instance of hudson.model.Run that is passed into SimpleBuildStep when running in a Pipeline job. I'm not sure if this is a bug or by design. I added the core and pipeline components because this is IMHO not something that can be fixed in Job DSL. At least not without using Pipeline specific API which I would like to avoid.

          Hi daspilker,

          Thanks for looking into this. Do you have any plans on how / if this can be resolved?

          Eamonn

          eamonn faherty added a comment - Hi daspilker , Thanks for looking into this. Do you have any plans on how / if this can be resolved? Eamonn

          Or do you have any work arounds where I can get the environment variable from within the job dsl?

          eamonn faherty added a comment - Or do you have any work arounds where I can get the environment variable from within the job dsl?

          With Job DSL 1.66, you can pass arbitrary parameters to Job DSL scripts from a Pipeline script (JENKINS-44128).

          Daniel Spilker added a comment - With Job DSL 1.66, you can pass arbitrary parameters to Job DSL scripts from a Pipeline script ( JENKINS-44128 ).

          Akshat Mehta added a comment -

          HI, When DSL 1.66 will be released ?

          Akshat Mehta added a comment - HI, When DSL 1.66 will be released ?

            daspilker Daniel Spilker
            anomalizer Arvind Jayaprakash
            Votes:
            8 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: