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

Active-Choice jenkinsProject variable is not available under Folder

      As a freestyle job at top level (not under any folder),
      the groovy script below is working
      for both "Active Choice Parameter" and "Active Choices Reactive Parameter":

      return [ jenkinsProject.getName() ]
      

      But when I move this same freestyle job under a "Cloudbees Folder",
      or when I use the same script in "Multibranch-MultiConfiguration" job
      then it will run the "Fallback script".

          [JENKINS-36590] Active-Choice jenkinsProject variable is not available under Folder

          Just added JENKINS-36590 to 1.5 release notes. 1.5 will be released soon (<4 weeks I believe, maybe in 1 week)

          Bruno P. Kinoshita added a comment - Just added JENKINS-36590 to 1.5 release notes. 1.5 will be released soon (<4 weeks I believe, maybe in 1 week)

          Rick Liu added a comment - - edited

          Does this fix also apply to tomultibranch-multiconfiguration job?

          Rick Liu added a comment - - edited Does this fix also apply to tomultibranch-multiconfiguration job?

          It should work, totoroliu. We are now searching all items in Jenkins, which Java object has class of, or subclass of Project.

          Would you have some spare minutes to give it a try? Attached you'll find the latest code compiled and built as a plug-in binary. You can run a test Jenkins with java -jar jenkins.war and install the plug-in and other required plug-ins (I never used multibranch-multiconfiguration I think). In case you are running it on a computer with Jenkins, you may want to define a different JENKINS_HOME while testing, so to not override the contents in the current installation.

          Thanks
          Bruno

          Bruno P. Kinoshita added a comment - It should work, totoroliu . We are now searching all items in Jenkins, which Java object has class of, or subclass of Project. Would you have some spare minutes to give it a try? Attached you'll find the latest code compiled and built as a plug-in binary. You can run a test Jenkins with java -jar jenkins.war and install the plug-in and other required plug-ins (I never used multibranch-multiconfiguration I think). In case you are running it on a computer with Jenkins, you may want to define a different JENKINS_HOME while testing, so to not override the contents in the current installation. Thanks Bruno

          Rick Liu added a comment - - edited

          I just downloaded and installed your patch plugin to my Jenkins test server with environment:
          Ubuntu 14.04 x86_64
          Jenkins 2.14
          Open JDK 1.7
          Active Choices Plug-in 1.5-alpha-2-SNAPSHOT (private-6a4828b0-kinoshitabd)
          Folders Plugin 5.12
          Multi-Branch Project Plugin 0.5.1

          I confirm that it's now working for freestyle job to access jenkinsProject variable under a folder.

          However,
          when I try it on a matrx job (multi-configuration) and a multibranch-multiconfiguration job outside a folder,
          I got the error for both jobs.

          Rick Liu added a comment - - edited I just downloaded and installed your patch plugin to my Jenkins test server with environment: Ubuntu 14.04 x86_64 Jenkins 2.14 Open JDK 1.7 Active Choices Plug-in 1.5-alpha-2-SNAPSHOT (private-6a4828b0-kinoshitabd) Folders Plugin 5.12 Multi-Branch Project Plugin 0.5.1 I confirm that it's now working for freestyle job to access jenkinsProject variable under a folder. However, when I try it on a matrx job (multi-configuration) and a multibranch-multiconfiguration job outside a folder, I got the error for both jobs.

          Rick Liu added a comment -

          Refer to JENKINS-32461

          "jenkinsProject variable is not available in Multi-configuration project" was broken already in Active-Choices 1.4

          Rick Liu added a comment - Refer to JENKINS-32461 "jenkinsProject variable is not available in Multi-configuration project" was broken already in Active-Choices 1.4

          Thanks for testing it totoroliu!!! Back to the blackboard

          Bruno P. Kinoshita added a comment - Thanks for testing it totoroliu !!! Back to the blackboard

          Hi again totoroliu,

          Had a play with the Multi Branch plug-in. It was my first time using or debugging the plug-in, so feel free to correct me if anything I say here is not correct.

          I had to install the multibranch and git plug-ins in my development environment. Then created a very simple job pointing to the active-choices-plugin repository, and with a single parameter. That generated one job for each branch in the GitHub repository (interestingly, after I removed one branch I had to save the project again to sync the local projects).

          The problem is that when you save a multibranch project, it invokes the project with parameters. At that moment, the active-choices plugin stores the project name, which at that moment contains only the multibranch project name (not its subproject name). Furthermore, the plugin has access to the web request. There it can look for things like form information submitted by the user.

          There I can see the branches names, which relate to the project names. But there is no clear way to find which of those branches, the current project will be assigned.

          So it's not easy (not sure if that's doable as well) to retrieve the correct project name.

          And the reason why the multibranch project name is not displayed, is because it is not a Project Java object, it is a TopLevelItem in Jenkins, that creates Projects (FreeStyleProject or MavenProject from what I understood from quickly sifting through the code base).

          totoroliu, if you really want this feature, I suggest we close this issue for projects under a Folder, and then you can create a separate issue for multibranch-multiconfiguration jobs. Then we can work on that issue later. Does that make sense to you?

          Bruno

          Bruno P. Kinoshita added a comment - Hi again totoroliu , Had a play with the Multi Branch plug-in. It was my first time using or debugging the plug-in, so feel free to correct me if anything I say here is not correct. I had to install the multibranch and git plug-ins in my development environment. Then created a very simple job pointing to the active-choices-plugin repository, and with a single parameter. That generated one job for each branch in the GitHub repository (interestingly, after I removed one branch I had to save the project again to sync the local projects). The problem is that when you save a multibranch project, it invokes the project with parameters. At that moment, the active-choices plugin stores the project name, which at that moment contains only the multibranch project name (not its subproject name). Furthermore, the plugin has access to the web request. There it can look for things like form information submitted by the user. There I can see the branches names, which relate to the project names. But there is no clear way to find which of those branches, the current project will be assigned. So it's not easy (not sure if that's doable as well) to retrieve the correct project name. And the reason why the multibranch project name is not displayed, is because it is not a Project Java object, it is a TopLevelItem in Jenkins, that creates Projects (FreeStyleProject or MavenProject from what I understood from quickly sifting through the code base). totoroliu , if you really want this feature, I suggest we close this issue for projects under a Folder, and then you can create a separate issue for multibranch-multiconfiguration jobs. Then we can work on that issue later. Does that make sense to you? Bruno

          Rick Liu added a comment -

          (interestingly, after I removed one branch I had to save the project again to sync the local projects).

          Yes,
          or you can manually trigger the sync by running "Branch indexing" again.

          Yes, sure no problem.
          Let's close this ticket.
          and maybe rename it for free-style job only.

          How about the regular matrix (multi-configuration) job?
          JENKINS-32461 seems still broken.

          Rick Liu added a comment - (interestingly, after I removed one branch I had to save the project again to sync the local projects). Yes, or you can manually trigger the sync by running "Branch indexing" again. Yes, sure no problem. Let's close this ticket. and maybe rename it for free-style job only. How about the regular matrix (multi-configuration) job? JENKINS-32461 seems still broken.

          Fixed for projects under folders. There will be another issue for multi-branch, and see for multi-configuration support JENKINS-32461

          Bruno P. Kinoshita added a comment - Fixed for projects under folders. There will be another issue for multi-branch, and see for multi-configuration support JENKINS-32461

          Included in 1.5.0

          Bruno P. Kinoshita added a comment - Included in 1.5.0

            kinow Bruno P. Kinoshita
            totoroliu Rick Liu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: