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

Parameterised build in jenkins: Not getting parameters as env variables

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Critical Critical

      Jenkins version: 2.6 - 2.9
      Host: Debian 8, Linux 63 bit machine, running in VM. ( jenkins installed through system repos and then updated.)
      Project type: Multi configuration project.
      Plugins:
      a) Build With Parameters: version 1.3
      b) Environment Injector Plugin: version 1.92.1
      c) Groovy: 1.29

      http://stackoverflow.com/questions/37786301/parameterised-build-in-jenkins-not-getting-parameters-as-shell-env-variables

      Problem: The parameterized build variables are not are not visible (as env variables) in the Execution step "shell script", They used to be visible in the older 1.x jenkins version.

      EDIT[2016-22-june]: THESE PARAMETERS ARE VISIBLE AS ENV VARIABLES ON MASTER BUT NOT ON THE SLAVES.

      Steps:

      Create a parameterized build with a multi configuration project.
      Add a parameter to the build (using This project is parameterized-> string parameter,

      {if that matters}

      ).
      Add a build step "Execute shell" to the job.

      Access these parameters in this shell script as env variables.

      echo "++++++++++++ building $lib_name ($lib_version) ++++++++++++++"

      Workaround--> for the time being, I have tried to create a groovy script in "Prepare an environment for the run" section. I created env variables using hardcoded values which are pased to shell script as env vars.

      def map = ['lib_name':'lib1']
      map['lib_version'] = 'master'
      return map

      This makes these "Hardcoded" variables visible in jenkins shell script..

      +++++++++++++++++++++++++++++++++++++++++++++++++++++++
      EDIT: 23-july-2016: (tested with adding section "Prepare an environment for the run"
      Logs from Master.
      [EnvInject] - Loading node environment variables.
      [EnvInject] - Preparing an environment for the build.
      [EnvInject] - Keeping Jenkins system variables.
      [EnvInject] - Keeping Jenkins build variables.
      [EnvInject] - Executing and processing the following script content:
      export BRANCH_NAME=${BRANCH_NAME}
      export BUILD_STAGE=${BUILD_STAGE}

      [****] $ /bin/bash -xe /tmp/hudson803008212850989562.sh
      + export BRANCH_NAME=feature/ABC
      + BRANCH_NAME=feature/ABC
      + export BUILD_STAGE=STAGE1
      + BUILD_STAGE=STAGE1

      ++++++++++++++++++++++++++++++++++++++++++++++++
      Logs from SLAVE.

      [EnvInject] - Inject global passwords.
      [EnvInject] - Mask passwords passed as build parameters.
      Gestartet durch vorgelagertes Projekt "COMPACT2", Build 1
      originally caused by:
      Gestartet durch Benutzer ABC DEF GHI
      [EnvInject] - Loading node environment variables.
      [EnvInject] - Preparing an environment for the build.
      [EnvInject] - Keeping Jenkins system variables.
      [EnvInject] - Keeping Jenkins build variables.
      [EnvInject] - Executing and processing the following script content:
      export BRANCH_NAME=${BRANCH_NAME}
      export BUILD_STAGE=${BUILD_STAGE}

      [****] $ /bin/bash -xe /tmp/hudson7212379337542594663.sh
      + export BRANCH_NAME=
      + BRANCH_NAME=
      + export BUILD_STAGE=
      + BUILD_STAGE=
      [EnvInject] - Script executed successfully.
      [EnvInject] - Injecting contributions.

          [JENKINS-35921] Parameterised build in jenkins: Not getting parameters as env variables

          Ashish Behl created issue -
          Ashish Behl made changes -
          Environment Original: Jenkins version: 2.6 - 2.9
          Host: Debian 8, Linux 63 bit machine, runninf in VM. ( jenkins installed through system repos and updated.)
          Project type: Multi configuration project.
          Plugins:
              a) Build With Parameters: version 1.3
              b) Environment Injector Plugin: version 1.92.1
              c) Groovy: 1.29
          New: Jenkins version: 2.6 - 2.9
          Host: Debian 8, Linux 63 bit machine, running in VM. ( jenkins installed through system repos and updated.)
          Project type: Multi configuration project.
          Plugins:
              a) Build With Parameters: version 1.3
              b) Environment Injector Plugin: version 1.92.1
              c) Groovy: 1.29
          Ashish Behl made changes -
          Environment Original: Jenkins version: 2.6 - 2.9
          Host: Debian 8, Linux 63 bit machine, running in VM. ( jenkins installed through system repos and updated.)
          Project type: Multi configuration project.
          Plugins:
              a) Build With Parameters: version 1.3
              b) Environment Injector Plugin: version 1.92.1
              c) Groovy: 1.29
          New: Jenkins version: 2.6 - 2.9
          Host: Debian 8, Linux 63 bit machine, running in VM. ( jenkins installed through system repos and then updated.)
          Project type: Multi configuration project.
          Plugins:
              a) Build With Parameters: version 1.3
              b) Environment Injector Plugin: version 1.92.1
              c) Groovy: 1.29
          Ashish Behl made changes -
          Description Original: http://stackoverflow.com/questions/37786301/parameterised-build-in-jenkins-not-getting-parameters-as-shell-env-variables

          Problem: The parameterized build variables are not are not visible (as env variables) in the Execution step "shell script", They used to be visible in the older 1.x jenkins version.

          Steps:

              Create a parameterized build with a multi configuration project.
              Add a parameter to the build (using This project is parameterized-> string parameter, {if that matters} ).
              Add a build step "Execute shell" to the job.

              Access these parameters in this shell script as env variables.

              echo "++++++++++++ building $lib_name ($lib_version) ++++++++++++++"

          Workaround--> for the time being, I have tried to create a groovy script in "Prepare an environment for the run" section. I created env variables using hardcoded values which are pased to shell script as env vars.

          def map = ['lib_name':'lib1']
          map['lib_version'] = 'master'
          return map

          New: http://stackoverflow.com/questions/37786301/parameterised-build-in-jenkins-not-getting-parameters-as-shell-env-variables

          Problem: The parameterized build variables are not are not visible (as env variables) in the Execution step "shell script", They used to be visible in the older 1.x jenkins version.

          Steps:

              Create a parameterized build with a multi configuration project.
              Add a parameter to the build (using This project is parameterized-> string parameter, {if that matters} ).
              Add a build step "Execute shell" to the job.

              Access these parameters in this shell script as env variables.

              echo "++++++++++++ building $lib_name ($lib_version) ++++++++++++++"

          Workaround--> for the time being, I have tried to create a groovy script in "Prepare an environment for the run" section. I created env variables using hardcoded values which are pased to shell script as env vars.

          def map = ['lib_name':'lib1']
          map['lib_version'] = 'master'
          return map

          This makes these "Hardcoded" variables visible in jenkins shell script..

          Ashish Behl made changes -
          Priority Original: Major [ 3 ] New: Critical [ 2 ]
          Ashish Behl made changes -
          Labels Original: environment-variables multi-configuration parameterized New: core environment-variables multi-configuration parameterized parameterized-trigger
          Ashish Behl made changes -
          Description Original: http://stackoverflow.com/questions/37786301/parameterised-build-in-jenkins-not-getting-parameters-as-shell-env-variables

          Problem: The parameterized build variables are not are not visible (as env variables) in the Execution step "shell script", They used to be visible in the older 1.x jenkins version.

          Steps:

              Create a parameterized build with a multi configuration project.
              Add a parameter to the build (using This project is parameterized-> string parameter, {if that matters} ).
              Add a build step "Execute shell" to the job.

              Access these parameters in this shell script as env variables.

              echo "++++++++++++ building $lib_name ($lib_version) ++++++++++++++"

          Workaround--> for the time being, I have tried to create a groovy script in "Prepare an environment for the run" section. I created env variables using hardcoded values which are pased to shell script as env vars.

          def map = ['lib_name':'lib1']
          map['lib_version'] = 'master'
          return map

          This makes these "Hardcoded" variables visible in jenkins shell script..

          New:  Jenkins version: 2.6 - 2.9
          Host: Debian 8, Linux 63 bit machine, running in VM. ( jenkins installed through system repos and then updated.)
          Project type: Multi configuration project.
          Plugins:
              a) Build With Parameters: version 1.3
              b) Environment Injector Plugin: version 1.92.1
              c) Groovy: 1.29

          http://stackoverflow.com/questions/37786301/parameterised-build-in-jenkins-not-getting-parameters-as-shell-env-variables

          Problem: The parameterized build variables are not are not visible (as env variables) in the Execution step "shell script", They used to be visible in the older 1.x jenkins version.

          Steps:

              Create a parameterized build with a multi configuration project.
              Add a parameter to the build (using This project is parameterized-> string parameter, {if that matters} ).
              Add a build step "Execute shell" to the job.

              Access these parameters in this shell script as env variables.

              echo "++++++++++++ building $lib_name ($lib_version) ++++++++++++++"

          Workaround--> for the time being, I have tried to create a groovy script in "Prepare an environment for the run" section. I created env variables using hardcoded values which are pased to shell script as env vars.

          def map = ['lib_name':'lib1']
          map['lib_version'] = 'master'
          return map

          This makes these "Hardcoded" variables visible in jenkins shell script..

          Ashish Behl made changes -
          Component/s New: build-with-parameters-plugin [ 17657 ]
          Ashish Behl made changes -
          Priority Original: Critical [ 2 ] New: Major [ 3 ]
          Ashish Behl made changes -
          Priority Original: Major [ 3 ] New: Critical [ 2 ]

            Unassigned Unassigned
            ashish_behl Ashish Behl
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: