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

jenkinsProject variable is not available in Multi-configuration project

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • active-choices-plugin
    • None
    • Jenkins ver. 1.625.3
      Active Choices Plug-in 1.3

      Matrix (multi-configuration) projects don't have access to jenkinsProject variable in Groovy script.

      Easy test:
      return [jenkinsProject]

      This is working on Freestyle project but not on Matrix.

        1. Selection_001.png
          Selection_001.png
          50 kB
        2. Selection_002.png
          Selection_002.png
          47 kB
        3. Selection_003.png
          Selection_003.png
          48 kB

          [JENKINS-32461] jenkinsProject variable is not available in Multi-configuration project

          Workaround: def jenkinsProject = hudson.model.Hudson.instance.getItem("PROJECT_NAME")

          Michal Kovarik added a comment - Workaround: def jenkinsProject = hudson.model.Hudson.instance.getItem("PROJECT_NAME")

          Code changed in jenkins
          User: Bruno P. Kinoshita
          Path:
          src/main/java/org/biouno/unochoice/AbstractScriptableParameter.java
          http://jenkins-ci.org/commit/active-choices-plugin/aa4f3bfbade87bad3f451a76fea54b412ab364c2
          Log:
          [FIXED JENKINS-32461] Look for parent with class = AbstractItem rather than Project. This way we include the MatrixProject, which derives from AbstractProject, and other classes too (the getName() method is in the AbstractItem class)

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Bruno P. Kinoshita Path: src/main/java/org/biouno/unochoice/AbstractScriptableParameter.java http://jenkins-ci.org/commit/active-choices-plugin/aa4f3bfbade87bad3f451a76fea54b412ab364c2 Log: [FIXED JENKINS-32461] Look for parent with class = AbstractItem rather than Project. This way we include the MatrixProject, which derives from AbstractProject, and other classes too (the getName() method is in the AbstractItem class)

          Rick Liu added a comment -

          While testing JENKINS-36590,
          I found out this bug still exists.

          My environment:
          Ubuntu 14.04 x86_64
          Jenkins 2.13
          Open JDK 1.7
          Active Choices Plug-in 1.4

          I created a multi-configuration job (matrix) on the top level (outside of Cloudsbee folder)
          with 2 intput parameters:
          Name1: Active choices parameter
          Name2: Active choices reactive parameter

          Both have Groovy script:
          return [ jenkinsProject.getName()]

          This Groovy script so far works only for freestyle jobs,
          but would fail for multi-configuration jobs or multibranch-multiconfiguration job
          or for jobs within a folder (eg. freestyle job would fail if it's under a folder).

          Rick Liu added a comment - While testing JENKINS-36590 , I found out this bug still exists. My environment: Ubuntu 14.04 x86_64 Jenkins 2.13 Open JDK 1.7 Active Choices Plug-in 1.4 I created a multi-configuration job (matrix) on the top level (outside of Cloudsbee folder) with 2 intput parameters: Name1: Active choices parameter Name2: Active choices reactive parameter Both have Groovy script: return [ jenkinsProject.getName()] This Groovy script so far works only for freestyle jobs, but would fail for multi-configuration jobs or multibranch-multiconfiguration job or for jobs within a folder (eg. freestyle job would fail if it's under a folder).

          Rick Liu added a comment -

          While testing JENKINS-36590,
          I found out this bug still exists.

          My environment:
          Ubuntu 14.04 x86_64
          Jenkins 2.13
          Open JDK 1.7
          Active Choices Plug-in 1.4

          I created a multi-configuration job (matrix) on the top level (outside of Cloudsbee folder)
          with 2 intput parameters:
          Name1: Active choices parameter
          Name2: Active choices reactive parameter

          Both have Groovy script:
          return [ jenkinsProject.getName()]

          This Groovy script so far works only for freestyle jobs,
          but would fail for multi-configuration jobs or multibranch-multiconfiguration job
          or for jobs within a folder (eg. freestyle job would fail if it's under a folder).

          Rick Liu added a comment - While testing JENKINS-36590 , I found out this bug still exists. My environment: Ubuntu 14.04 x86_64 Jenkins 2.13 Open JDK 1.7 Active Choices Plug-in 1.4 I created a multi-configuration job (matrix) on the top level (outside of Cloudsbee folder) with 2 intput parameters: Name1: Active choices parameter Name2: Active choices reactive parameter Both have Groovy script: return [ jenkinsProject.getName()] This Groovy script so far works only for freestyle jobs, but would fail for multi-configuration jobs or multibranch-multiconfiguration job or for jobs within a folder (eg. freestyle job would fail if it's under a folder).

          Right, so the issue for multi-configuration projects, is that let's say you create a job called "my job". And there you configured an axis, say, "country", with values "brazil argentina colombia".

          The moment you persist the job, by clicking apply or save, Jenkins stores the job configuration with the parameters. The active-choices parameters are persisted with the job name, i.e. "my job".

          When you click to execute the job with parameter in Jenkins, what the plug-in receives then, are values such as "country=brazil", "country=argentina", and "country=colombia". That's because of the way multi-configuration jobs are created in Jenkins.

          Bruno P. Kinoshita added a comment - Right, so the issue for multi-configuration projects, is that let's say you create a job called "my job". And there you configured an axis, say, "country", with values "brazil argentina colombia". The moment you persist the job, by clicking apply or save, Jenkins stores the job configuration with the parameters. The active-choices parameters are persisted with the job name, i.e. "my job". When you click to execute the job with parameter in Jenkins, what the plug-in receives then, are values such as "country=brazil", "country=argentina", and "country=colombia". That's because of the way multi-configuration jobs are created in Jenkins.

          Rick Liu added a comment -

          so I assume

          return [ jenkinsProject.getName()]
          

          should return "my job"?

          Rick Liu added a comment - so I assume return [ jenkinsProject.getName()] should return "my job"?

          Except that when we scan Jenkins for projects, we are trying to match "my job" with one of the possible axes' names, like "country=colombia".

          As the values do not match, the jenkinsProject object is null.

          When the job is persisted, we store the project name. And when the screen to execute the job is called, we scan Jenkins trying to retrieve the object to inject into groovy.

          Perhaps we could try getting the project name, the moment the user loads the job execution screen.

          We can start the work now, but I'm not sure if I'll have time to finish the work before the next release. So it will be probably released around September, unless I get some funding to work on this issue from work (not very likely at the moment)

          But will start working in the next days hopefully with users responding so prompt like you it will be much easier to fix it.

          Bruno P. Kinoshita added a comment - Except that when we scan Jenkins for projects, we are trying to match "my job" with one of the possible axes' names, like "country=colombia". As the values do not match, the jenkinsProject object is null. When the job is persisted, we store the project name. And when the screen to execute the job is called, we scan Jenkins trying to retrieve the object to inject into groovy. Perhaps we could try getting the project name, the moment the user loads the job execution screen. We can start the work now, but I'm not sure if I'll have time to finish the work before the next release. So it will be probably released around September, unless I get some funding to work on this issue from work (not very likely at the moment) But will start working in the next days hopefully with users responding so prompt like you it will be much easier to fix it.

          Kevin Yu added a comment -

          Hi kinow Any update on this JIRA?

          Thanks.

          Kevin Yu added a comment - Hi kinow Any update on this JIRA? Thanks.

          Hi samsun387, triaged this issue for 1.5.4 release. Will spend some time looking into how to fix this issue, but cannot promise including it in the release. I remember it was a bit tricky due to the way we retrieve the project name.

          Bruno P. Kinoshita added a comment - Hi samsun387 , triaged this issue for 1.5.4 release. Will spend some time looking into how to fix this issue, but cannot promise including it in the release. I remember it was a bit tricky due to the way we retrieve the project name.

            kinow Bruno P. Kinoshita
            mkovarik Michal Kovarik
            Votes:
            5 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: