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

Remote API for creating a new Job is not working - using createItem

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Not A Defect
    • Component/s: core
    • Labels:
      None
    • Environment:
      CentOS 5.0, Jenkins ver. 1.406
      Fedora 13, Jenkins 1.415, Tomcat 6.0.26

      Description

      I am trying to create a new job using Remote API. I am getting an "No Mode Error".
      When I copy a job it is working but I am not able to run the build and getting Job is not buildable.
      I have to disable and enable the job using remote api to make it work. There should be a way to save the job using remote api.

      http://192.168.1.69:8080/createItem?name=ePaaSCompleteDemo_05
      Here is the Request Body
      ========================
      <?xml version='1.0' encoding='UTF-8'?>
      <maven2-moduleset>
      <actions/>
      <description></description>
      <logRotator>
      <daysToKeep>-1</daysToKeep>
      <numToKeep>-1</numToKeep>
      <artifactDaysToKeep>-1</artifactDaysToKeep>
      <artifactNumToKeep>-1</artifactNumToKeep>
      </logRotator>
      <keepDependencies>false</keepDependencies>
      <properties/>
      <scm class="hudson.plugins.git.GitSCM">
      <configVersion>1</configVersion>
      <remoteRepositories>
      <org.spearce.jgit.transport.RemoteConfig>
      <string>com.epaas.completedemo</string>
      <int>5</int>
      <string>fetch</string>
      <string>+refs/heads/:refs/remotes/com.epaas.completedemo/</string>
      <string>receivepack</string>
      <string>git-upload-pack</string>
      <string>uploadpack</string>
      <string>git-upload-pack</string>
      <string>url</string>
      <string>git://github.com/arjunballa/com.epaas.completedemo.git</string>
      <string>tagopt</string>
      <string></string>
      </org.spearce.jgit.transport.RemoteConfig>
      </remoteRepositories>
      <branches>
      <hudson.plugins.git.BranchSpec>
      <name>**</name>
      </hudson.plugins.git.BranchSpec>
      </branches>
      <mergeOptions/>
      <recursiveSubmodules>false</recursiveSubmodules>
      <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
      <authorOrCommitter>false</authorOrCommitter>
      <clean>false</clean>
      <wipeOutWorkspace>false</wipeOutWorkspace>
      <pruneBranches>false</pruneBranches>
      <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
      <gitTool>Default</gitTool>
      <submoduleCfg class="list"/>
      <relativeTargetDir></relativeTargetDir>
      <excludedRegions></excludedRegions>
      <excludedUsers></excludedUsers>
      <skipTag>false</skipTag>
      </scm>
      <canRoam>true</canRoam>
      <disabled>false</disabled>
      <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
      <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
      <triggers class="vector"/>
      <concurrentBuild>false</concurrentBuild>
      <rootModule>
      <groupId>com.epaas.completedemo</groupId>
      <artifactId>com.epaas.completedemo.parent</artifactId>
      </rootModule>
      <goals>clean deploy</goals>
      <aggregatorStyleBuild>true</aggregatorStyleBuild>
      <incrementalBuild>false</incrementalBuild>
      <usePrivateRepository>false</usePrivateRepository>
      <ignoreUpstremChanges>false</ignoreUpstremChanges>
      <archivingDisabled>false</archivingDisabled>
      <resolveDependencies>false</resolveDependencies>
      <processPlugins>false</processPlugins>
      <mavenValidationLevel>-1</mavenValidationLevel>
      <reporters/>
      <publishers/>
      <buildWrappers/>
      </maven2-moduleset>
      ===========================
      [Winstone 2011/04/17 21:46:49] - Untrapped Error in Servlet
      javax.servlet.ServletException: java.lang.IllegalArgumentException: java.lang.Nu
      llPointerException
      at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:603)
      at org.kohsuke.stapler.Stapler.invoke(Stapler.java:646)
      at org.kohsuke.stapler.Stapler.invoke(Stapler.java:477)
      at org.kohsuke.stapler.Stapler.service(Stapler.java:159)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
      at winstone.ServletConfiguration.execute(ServletConfiguration.java:249)
      at winstone.RequestDispatcher.forward(RequestDispatcher.java:335)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:378)
      at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:9
      4)
      at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:86)

      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:47)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.
      java:84)
      at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.ja
      va:76)
      at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:164)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.
      java:81)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at winstone.RequestDispatcher.forward(RequestDispatcher.java:333)
      at winstone.RequestHandlerThread.processRequest(RequestHandlerThread.jav
      a:244)
      at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
      at java.lang.Thread.run(Thread.java:636)
      Caused by: java.lang.IllegalArgumentException: java.lang.NullPointerException
      at hudson.model.ItemGroupMixIn.createProject(ItemGroupMixIn.java:248)
      at hudson.model.ItemGroupMixIn.createTopLevelItem(ItemGroupMixIn.java:17
      3)
      at hudson.model.Hudson.doCreateItem(Hudson.java:2758)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:28
      2)
      at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:149)
      at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.j
      ava:88)
      at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:103)
      at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.
      java:53)
      at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:561)
      ... 26 more
      Caused by: java.lang.NullPointerException
      at hudson.model.ItemGroupMixIn.createProject(ItemGroupMixIn.java:246)
      ... 38 more

      Apr 17, 2011 11:13:05 PM hudson.model.AsyncPeriodicWork$1 run
      INFO: Started Workspace clean-up
      Apr 17, 2011 11:13:05 PM hudson.model.AsyncPeriodicWork$1 run
      INFO: Finished Workspace clean-up. 56 ms
      [webapp 2011/04/17 23:36:03] - Error while serving http://192.168.1.69:8080/crea
      teItem
      java.lang.reflect.InvocationTargetException
      at sun.reflect.GeneratedMethodAccessor286.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:28
      2)
      at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:149)
      at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.j
      ava:88)
      at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:103)
      at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.
      java:53)
      at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:561)
      at org.kohsuke.stapler.Stapler.invoke(Stapler.java:646)
      at org.kohsuke.stapler.Stapler.invoke(Stapler.java:477)
      at org.kohsuke.stapler.Stapler.service(Stapler.java:159)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
      at winstone.ServletConfiguration.execute(ServletConfiguration.java:249)
      at winstone.RequestDispatcher.forward(RequestDispatcher.java:335)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:378)
      at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:9
      4)
      at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:86)

      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:47)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.
      java:84)
      at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.ja
      va:76)
      at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:164)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.
      java:81)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at winstone.RequestDispatcher.forward(RequestDispatcher.java:333)
      at winstone.RequestHandlerThread.processRequest(RequestHandlerThread.jav
      a:244)
      at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
      at java.lang.Thread.run(Thread.java:636)
      Caused by: java.lang.NullPointerException
      at hudson.model.ItemGroupMixIn.createTopLevelItem(ItemGroupMixIn.java:14
      8)
      at hudson.model.Hudson.doCreateItem(Hudson.java:2758)
      ... 35 more

      [Winstone 2011/04/17 23:36:03] - Untrapped Error in Servlet
      javax.servlet.ServletException: java.lang.NullPointerException
      at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:603)
      at org.kohsuke.stapler.Stapler.invoke(Stapler.java:646)
      at org.kohsuke.stapler.Stapler.invoke(Stapler.java:477)
      at org.kohsuke.stapler.Stapler.service(Stapler.java:159)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
      at winstone.ServletConfiguration.execute(ServletConfiguration.java:249)
      at winstone.RequestDispatcher.forward(RequestDispatcher.java:335)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:378)
      at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:9
      4)
      at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:86)

      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:47)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.
      java:84)
      at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.ja
      va:76)
      at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:164)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.
      java:81)
      at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
      at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
      at winstone.RequestDispatcher.forward(RequestDispatcher.java:333)
      at winstone.RequestHandlerThread.processRequest(RequestHandlerThread.jav
      a:244)
      at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
      at java.lang.Thread.run(Thread.java:636)
      Caused by: java.lang.NullPointerException
      at hudson.model.ItemGroupMixIn.createTopLevelItem(ItemGroupMixIn.java:14
      8)
      at hudson.model.Hudson.doCreateItem(Hudson.java:2758)
      at sun.reflect.GeneratedMethodAccessor286.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:28
      2)
      at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:149)
      at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.j
      ava:88)
      at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:103)
      at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.
      java:53)
      at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:561)
      ... 26 more

      [root@localhost jenkins]#

        Activity

        Hide
        dannystaple Danny Staple added a comment -

        Also seeing the same issue here.
        When posting my job I get a response with the following snippet in it:
        <h1>Error</h1><p>No mode given</p>

        Show
        dannystaple Danny Staple added a comment - Also seeing the same issue here. When posting my job I get a response with the following snippet in it: <h1>Error</h1><p>No mode given</p>
        Hide
        dannystaple Danny Staple added a comment -

        Clarified environments.

        Show
        dannystaple Danny Staple added a comment - Clarified environments.
        Hide
        dannystaple Danny Staple added a comment -

        For those trying this - can I suggest using the hudson/jenkins cli:

        java -jar jenkins-cli.jar -s http://hudsonmaster:8080/jenkins create-job --username <username> --password <password> <job name> <config.xml

        This worked for me.

        Show
        dannystaple Danny Staple added a comment - For those trying this - can I suggest using the hudson/jenkins cli: java -jar jenkins-cli.jar -s http://hudsonmaster:8080/jenkins create-job --username <username> --password <password> <job name> <config.xml This worked for me.
        Hide
        kevinsawicki Kevin Sawicki added a comment -

        Did you try setting the Content-Type header of the request to either application/xml or text/xml ?

        Show
        kevinsawicki Kevin Sawicki added a comment - Did you try setting the Content-Type header of the request to either application/xml or text/xml ?
        Hide
        pszwed Piotr Szwed added a comment -

        I just found the same issue but after some investigation I discovered some workaround by invoking following commands in sequence:

        j.copy_job('trunk','trunk-new')
        j.disable_job('trunk-new')
        j.enable_job('trunk-new')

        Show
        pszwed Piotr Szwed added a comment - I just found the same issue but after some investigation I discovered some workaround by invoking following commands in sequence: j.copy_job('trunk','trunk-new') j.disable_job('trunk-new') j.enable_job('trunk-new')
        Hide
        arangamani Kannan Manickam added a comment -

        I had the same issue. As Kevin Sawicki said, I set the content_type which resolved this issue for me.

        Show
        arangamani Kannan Manickam added a comment - I had the same issue. As Kevin Sawicki said, I set the content_type which resolved this issue for me.
        Hide
        danielbeck Daniel Beck added a comment -

        User error, and the docs have been extended to mention the Content-Type requirement a while ago.

        Create Job

        To create a new job, post config.xml to this URL with query parameter name=JOBNAME. You need to send a Content-Type: application/xml header. You'll get 200 status code if the creation is successful, or 4xx/5xx code if it fails.

        Show
        danielbeck Daniel Beck added a comment - User error, and the docs have been extended to mention the Content-Type requirement a while ago. Create Job To create a new job, post config.xml to this URL with query parameter name=JOBNAME. You need to send a Content-Type: application/xml header. You'll get 200 status code if the creation is successful, or 4xx/5xx code if it fails.

          People

          • Assignee:
            Unassigned
            Reporter:
            arjunballa Arjun Balla
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: