• Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • 2.396

      Hello,

      It's not possible to create a view from the API, since the views are part of the Hudson config.xml itself, it seems that the createItem URL doesn't match the need as it looks designed to create the new config.xml for a dedicated job.

      The REST API could be some thing like:

      GET http://myserver:8080/view (All views)
      GET http://myserver:8080/view/myView (switch to Specific view - myView)
      POST http://myserver:8080/view (Create new view as defined in the posted XML)

      Can you please have a look?

      Thanks and regards,

      Julien

          [JENKINS-8927] Create a view from the XML API

          Nalin Makar added a comment -

          another option:

          java -jar jenkins-cli.jar -s <jenkins_url> groovy createView.groovy --username <user> --password <passwd>

          where createView.groovy contains

          hudson.model.Hudson.instance.addView(new hudson.model.ListView("ViewX"))

          Nalin Makar added a comment - another option: java -jar jenkins-cli.jar -s <jenkins_url> groovy createView.groovy --username <user> --password <passwd> where createView.groovy contains hudson.model.Hudson.instance.addView(new hudson.model.ListView("ViewX"))

          Patrik Boström added a comment - - edited

          Found this by looking through the source code:
          It is possible in Jenkins 1.509.4 to create views via the REST api

          view.xml:

           
          <?xml version="1.0" encoding="UTF-8"?>
          <hudson.model.ListView>
          <name>MyView</name>
          <filterExecutors>false</filterExecutors>
          <filterQueue>false</filterQueue>
          <properties class="hudson.model.View$PropertyList"/>
          <jobNames>
          <comparator class="hudson.util.CaseInsensitiveComparator"/>
          </jobNames>
          <jobFilters/>
          <columns>
          <hudson.views.StatusColumn/>
          <hudson.views.WeatherColumn/>
          <hudson.views.JobColumn/>
          <hudson.views.LastSuccessColumn/>
          <hudson.views.LastFailureColumn/>
          <hudson.views.LastDurationColumn/>
          <hudson.views.BuildButtonColumn/>
          </columns>
          </hudson.model.ListView>
          

          Create the view:

          curl -vvv -X POST -d @view.xml -H "Content-Type: text/xml" http://localhost:8080/jenkins/createView?name=MyView
          

          Get the configuration:

          curl http://localhost:8080/jenkins/view/MyView/config.xml
          

          Update the view:

          curl -X POST -d @view.xml -H "Content-Type: text/xml" http://localhost:8080/jenkins/view/MyView/config.xml
          

          Patrik Boström added a comment - - edited Found this by looking through the source code: It is possible in Jenkins 1.509.4 to create views via the REST api view.xml: <?xml version= "1.0" encoding= "UTF-8" ?> <hudson.model.ListView> <name> MyView </name> <filterExecutors> false </filterExecutors> <filterQueue> false </filterQueue> <properties class= "hudson.model.View$PropertyList" /> <jobNames> <comparator class= "hudson.util.CaseInsensitiveComparator" /> </jobNames> <jobFilters/> <columns> <hudson.views.StatusColumn/> <hudson.views.WeatherColumn/> <hudson.views.JobColumn/> <hudson.views.LastSuccessColumn/> <hudson.views.LastFailureColumn/> <hudson.views.LastDurationColumn/> <hudson.views.BuildButtonColumn/> </columns> </hudson.model.ListView> Create the view: curl -vvv -X POST -d @view.xml -H "Content-Type: text/xml" http://localhost:8080/jenkins/createView?name=MyView Get the configuration: curl http://localhost:8080/jenkins/view/MyView/config.xml Update the view: curl -X POST -d @view.xml -H "Content-Type: text/xml" http://localhost:8080/jenkins/view/MyView/config.xml

          Oleg Nenashev added a comment -

          @Patrik
          Should we consider the issue as "Resolved"?

          Oleg Nenashev added a comment - @Patrik Should we consider the issue as "Resolved"?

          Daniel Beck added a comment -

          Oleg: Needs to be documented on the /view/Foo/api page, similar to 'Create Job' on /api.

          Daniel Beck added a comment - Oleg: Needs to be documented on the /view/Foo/api page, similar to 'Create Job' on /api.

          Lukasz Tasz added a comment -

          this solution works pretty well with few limitation:

          • nestedView plugin does not register it's own class and curl end with exception that NestedView is not resolved.
          • in case of subviews, xml needs to be extended with <parent> node, unfortunately in case of coping view a to b, parent node is not visible.

          Lukasz Tasz added a comment - this solution works pretty well with few limitation: nestedView plugin does not register it's own class and curl end with exception that NestedView is not resolved. in case of subviews, xml needs to be extended with <parent> node, unfortunately in case of coping view a to b, parent node is not visible.

          patbos oleg_nenashev
          May I know the folder location of my view configuration page.

          curl http://localhost:8080/jenkins/view/MyView/config.xml is not working for me.

          -raja

          rajasekaran radhakrishnan added a comment - patbos oleg_nenashev May I know the folder location of my view configuration page. curl http://localhost:8080/jenkins/view/MyView/config.xml is not working for me. -raja

          rajasekaran radhakrishnan added a comment - - edited

          Also I am unable to create new view using curl

          curl -vvv -X POST -d @viewconfig.xml -H "Content-Type: text/xml" http://localhost:8080/jenkins/createView?name=My-Test-View -u admin:e973b7863cbsa11dsacdf2cd9db758091
          Note: Unnecessary use of -X or --request, POST is already inferred.

          • Trying 127.0.0.1...
          • Connected to localhost (127.0.0.1) port 8080 (#0)
          • Server auth using Basic with user 'admin'
            > POST /jenkins/createView?name=My-Test-View HTTP/1.1
            > Host: localhost:8080
            > Authorization: Basic YWRtaW46ZTk3M2dsDYzY2IwNTExNzlhY2FmDEWViNzIwOTE=
            > User-Agent: curl/7.47.0
            > Accept: /
            > Content-Type: text/xml
            > Content-Length: 1410
            > Expect: 100-continue
            >
            < HTTP/1.1 404 Not Found
            < Date: Wed, 01 Feb 2017 12:00:48 GMT
            < X-Content-Type-Options: nosniff
            < Content-Type: text/html; charset=ISO-8859-1
            < Cache-Control: must-revalidate,no-cache,no-store
            < Content-Length: 302
            < Connection: close
            < Server: Jetty(9.2.z-SNAPSHOT)
            <
            <html>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <title>Error 404 Not Found</title>
            </head>
            <body><h2>HTTP ERROR 404</h2>
            <p>Problem accessing /jenkins/createView. Reason:
            <pre> Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

          </body>
          </html>

          • Closing connection 0

          rajasekaran radhakrishnan added a comment - - edited Also I am unable to create new view using curl curl -vvv -X POST -d @viewconfig.xml -H "Content-Type: text/xml" http://localhost:8080/jenkins/createView?name=My-Test-View -u admin:e973b7863cbsa11dsacdf2cd9db758091 Note: Unnecessary use of -X or --request, POST is already inferred. Trying 127.0.0.1... Connected to localhost (127.0.0.1) port 8080 (#0) Server auth using Basic with user 'admin' > POST /jenkins/createView?name=My-Test-View HTTP/1.1 > Host: localhost:8080 > Authorization: Basic YWRtaW46ZTk3M2dsDYzY2IwNTExNzlhY2FmDEWViNzIwOTE= > User-Agent: curl/7.47.0 > Accept: / > Content-Type: text/xml > Content-Length: 1410 > Expect: 100-continue > < HTTP/1.1 404 Not Found < Date: Wed, 01 Feb 2017 12:00:48 GMT < X-Content-Type-Options: nosniff < Content-Type: text/html; charset=ISO-8859-1 < Cache-Control: must-revalidate,no-cache,no-store < Content-Length: 302 < Connection: close < Server: Jetty(9.2.z-SNAPSHOT) < <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Error 404 Not Found</title> </head> <body><h2>HTTP ERROR 404</h2> <p>Problem accessing /jenkins/createView. Reason: <pre> Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/> </body> </html> Closing connection 0

          PFB the error while creating new view.

          curl -X POST 'http://admin:password@localhost:8080/jenkins/createView?name=My-Test-View' --data-binary @viewconfig.xml -H "Content-Type: text/xml"

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
          <title>Error 404 Not Found</title>
          </head>
          <body><h2>HTTP ERROR 404</h2>
          <p>Problem accessing /jenkins/createView. Reason:
          <pre> Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

          </body>
          </html>

          My configuration file lokks:

          <?xml version="1.0" encoding="UTF-8"?>
          <au.com.centrumsystems.hudson.plugin.buildpipeline.BuildPipelineView plugin="build-pipeline-plugin@1.5.6">
          <name>my-test-view</name>
          <description>my-test-view for check</description>
          <filterExecutors>false</filterExecutors>
          <filterQueue>false</filterQueue>
          <properties class="hudson.model.View$PropertyList"/>
          <gridBuilder class="au.com.centrumsystems.hudson.plugin.buildpipeline.DownstreamProjectGridBuilder">
          <firstJob>ecs-testing</firstJob>
          <firstJobLink>job/ecs-testing/</firstJobLink>
          </gridBuilder>
          <noOfDisplayedBuilds>2</noOfDisplayedBuilds>
          <buildViewTitle>my-test-view for check</buildViewTitle>
          <consoleOutputLinkStyle>Lightbox</consoleOutputLinkStyle>
          <cssUrl></cssUrl>
          <triggerOnlyLatestJob>false</triggerOnlyLatestJob>
          <alwaysAllowManualTrigger>false</alwaysAllowManualTrigger>
          <showPipelineParameters>false</showPipelineParameters>
          <rowHeaders class="au.com.centrumsystems.hudson.plugin.buildpipeline.extension.SimpleRowHeader"/>
          <showPipelineParametersInHeaders>false</showPipelineParametersInHeaders>
          <columnHeaders class="au.com.centrumsystems.hudson.plugin.buildpipeline.extension.NullColumnHeader"/>
          <startsWithParameters>false</startsWithParameters>
          <refreshFrequency>3</refreshFrequency>
          <showPipelineDefinitionHeader>false</showPipelineDefinitionHeader>
          </au.com.centrumsystems.hudson.plugin.buildpipeline.BuildPipelineView>

          Regards,
          Raja

          rajasekaran radhakrishnan added a comment - PFB the error while creating new view. curl -X POST 'http://admin:password@localhost:8080/jenkins/createView?name=My-Test-View' --data-binary @viewconfig.xml -H "Content-Type: text/xml" <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Error 404 Not Found</title> </head> <body><h2>HTTP ERROR 404</h2> <p>Problem accessing /jenkins/createView. Reason: <pre> Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/> </body> </html> My configuration file lokks: <?xml version="1.0" encoding="UTF-8"?> <au.com.centrumsystems.hudson.plugin.buildpipeline.BuildPipelineView plugin="build-pipeline-plugin@1.5.6"> <name>my-test-view</name> <description>my-test-view for check</description> <filterExecutors>false</filterExecutors> <filterQueue>false</filterQueue> <properties class="hudson.model.View$PropertyList"/> <gridBuilder class="au.com.centrumsystems.hudson.plugin.buildpipeline.DownstreamProjectGridBuilder"> <firstJob>ecs-testing</firstJob> <firstJobLink>job/ecs-testing/</firstJobLink> </gridBuilder> <noOfDisplayedBuilds>2</noOfDisplayedBuilds> <buildViewTitle>my-test-view for check</buildViewTitle> <consoleOutputLinkStyle>Lightbox</consoleOutputLinkStyle> <cssUrl></cssUrl> <triggerOnlyLatestJob>false</triggerOnlyLatestJob> <alwaysAllowManualTrigger>false</alwaysAllowManualTrigger> <showPipelineParameters>false</showPipelineParameters> <rowHeaders class="au.com.centrumsystems.hudson.plugin.buildpipeline.extension.SimpleRowHeader"/> <showPipelineParametersInHeaders>false</showPipelineParametersInHeaders> <columnHeaders class="au.com.centrumsystems.hudson.plugin.buildpipeline.extension.NullColumnHeader"/> <startsWithParameters>false</startsWithParameters> <refreshFrequency>3</refreshFrequency> <showPipelineDefinitionHeader>false</showPipelineDefinitionHeader> </au.com.centrumsystems.hudson.plugin.buildpipeline.BuildPipelineView> Regards, Raja

          Daniel Beck added a comment -

          rajraja This is an issue tracker, not a support site. Please don't ask support type questions here. (Also, please don't ask where to ask. Just search a bit.)

          Daniel Beck added a comment - rajraja This is an issue tracker, not a support site. Please don't ask support type questions here. (Also, please don't ask where to ask. Just search a bit.)

          Denys Digtiar added a comment -

          I have created https://github.com/jenkinsci/jenkins/pull/7692 to address the missing documentation.

          Denys Digtiar added a comment - I have created https://github.com/jenkinsci/jenkins/pull/7692 to address the missing documentation.

            duemir Denys Digtiar
            foch Julien Faucher
            Votes:
            9 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: