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

New jenkins job doesn't get added to the Dashboard view using Python Jenkins

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: python-plugin
    • Labels:
      None
    • Environment:
      Jenkins ver. 2.138.1
    • Similar Issues:

      Description

      Hello there!

      We have a requirement where we add the jenkins job for the newly created branch to the Dashboard/Hotfixes view.

      The python tool when run for Hotfix branch gets added to the Hotfixes view cleanly. But, when we create a feature branch that has to get added to the Dashboard it doesn't get added.

      Note: Here view variable is either Dashboard or Hotfixes
      view_path = 'all/job/USM/view/{}'.format(view)
      view_cfg = server.get_view_config(view_path)
      update_cfg = []
      for num, line in enumerate(view_cfg.splitlines(), start=1):
          if line.strip().startswith('</jobNames>'):
              spaces = ' ' * 4
              update_cfg.append(u'{}<string>{}</string>'.format(spaces, branch))
           update_cfg.append(line)
      server.reconfig_view(view_path, new_view_cfg)

      Here we read the conflig xml of the view we want the job to be added.
      Then, we add the new branch before the jobNames end in the config xml file.
      Lastly, we update the view using reconfig_view.

      Not sure why the new job doesn't get added to the Dashboard view. But works fine when we added it to say Hotfixes view.

      Please advise if I am missing something here.

        Attachments

          Activity

          Hide
          matebende Máté Csanády added a comment - - edited

          Hi Vineeth!

          I am suffering from the same problem.

          Have you come up with a solution since july?

          Thanks.

          Show
          matebende Máté Csanády added a comment - - edited Hi Vineeth! I am suffering from the same problem. Have you come up with a solution since july? Thanks.
          Hide
          vkarkad Vineeth Karkad added a comment -

          Hi Máté! 

          Thanks for chiming in. We haven't come up with any solution as yet. Hopefully this ticket gets attention of the right folks and prioritised to get fixed.

          Show
          vkarkad Vineeth Karkad added a comment - Hi Máté!  Thanks for chiming in. We haven't come up with any solution as yet. Hopefully this ticket gets attention of the right folks and prioritised to get fixed.
          Hide
          matebende Máté Csanády added a comment -

          Hi Vineeth!

          I've fonund a workaround. I know, that it's not the solution, but solves your problem, while there is no fix for the bug.

          I run a groovy script on the server, that adds the job under the specified view. My code:

          view = "MyView"
          job = "MyJob" 
          
          try:
                      script = "import jenkins.model.Jenkins\nJenkins jenkins = Jenkins.getInstance()\nmyView = hudson.model.Hudson.instance.getView(\"" + view + "\")\nmyView.doAddJobToView(\"" + job + "\")"
                      server.run_script(script)
                      save = "import jenkins.model.Jenkins\nJenkins jenkins = Jenkins.getInstance()\njenkins.save()"
                      server.run_script(save)
          except Exception, e:
                      print("Cannot add job under the specified view\n" + str(e).decode("utf-8"))  
          Show
          matebende Máté Csanády added a comment - Hi Vineeth! I've fonund a workaround. I know, that it's not the solution, but solves your problem, while there is no fix for the bug. I run a groovy script on the server, that adds the job under the specified view. My code: view = "MyView" job = "MyJob" try : script = " import jenkins.model.Jenkins\nJenkins jenkins = Jenkins.getInstance()\nmyView = hudson.model.Hudson.instance.getView(\" " + view + " \ ")\nmyView.doAddJobToView(\" " + job + " \ ")" server.run_script(script) save = " import jenkins.model.Jenkins\nJenkins jenkins = Jenkins.getInstance()\njenkins.save()" server.run_script(save) except Exception, e: print( "Cannot add job under the specified view\n" + str(e).decode( "utf-8" ))
          Hide
          vkarkad Vineeth Karkad added a comment -

          Hi Máté! 

          Phew, this is awesome! I will try it out and update you on how it goes..Thanks a bunch, really appreciate it.

           

          Show
          vkarkad Vineeth Karkad added a comment - Hi Máté!  Phew, this is awesome! I will try it out and update you on how it goes..Thanks a bunch, really appreciate it.  
          Hide
          matebende Máté Csanády added a comment -

          Hi Vineeth!
          Could you try it out? How did it go? Do sou need any help?
          Máté

          Show
          matebende Máté Csanády added a comment - Hi Vineeth! Could you try it out? How did it go? Do sou need any help? Máté

            People

            • Assignee:
              jhasse Jan Niklas Hasse
              Reporter:
              vkarkad Vineeth Karkad
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: