How can I change a build configuration step through the API?

the documentation states:

Build configuration steps: GET/DELETE http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/steps/<step_id>
Create build configuration step: POST http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/steps The XML posted is the same as retrieved by GET request to .../steps/<step_id>

but when I use the following as a POST:

http://myteamcity/httpAuth/app/rest/buildTypes/id:Testing_project_branch/steps/RUNNER_34

with content-type application/xml and the following xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<step id="RUNNER_34" name="testing Deploy Branch Build" type="octopus.deploy.release">
    <properties>
        <property name="octopus_deployto" value="%env.deploy_target%"/>
        <property name="octopus_host" value="octopus.server.com"/>
        <property name="octopus_project_name" value="%env.OCTOPUS_PROJECT%"/>
        <property name="octopus_releasenumber" value="%env.BUILD_NUMBER%"/>
        <property name="octopus_version" value="2.0+"/>
        <property name="octopus_waitfordeployments" value="true"/>
        <property name="secure:octopus_apikey"/>
        <property name="teamcity.step.mode" value="default"/>
    </properties>
</step>

I get the following error message:

Error has occurred during request processing (405).
Error: javax.ws.rs.WebApplicationException
Not supported request. Please check URL, HTTP method and transfered data are correct. metadata: [Allow:[GET,DELETE,OPTIONS,HEAD,PUT],]


note that it says PUT and not POST. So following that advice I can change it to a PUT and I am greeted with the following message:


Error has occurred during request processing (Internal Server Error).
Error: java.lang.RuntimeException: java.lang.NullPointerException, caused by: java.lang.NullPointerException
Error occurred while processing this request.

I have tried taking the step name out of the url and or using an existing step to overwrite instead of create. Nothing seems to be working. What am I doing incorrectly?

6 comments
Comment actions Permalink

Hi,

The difference between POST and PUT:

  • POST: creates the entity in the request adding it to the existing collection;
  • PUT: based on the existence of the entity, creates or updates the entity in the request.


Here is the examples of working requests:

curl --basic --user name:password --request POST http://localhost:8111/httpAuth/app/rest/buildTypes/id:HelloWorld_Build1/steps --data @rest_create_step.xml --header "Content-Type: application/xml"
curl --basic --user name:password --request PUT   http://localhost:8111/httpAuth/app/rest/buildTypes/id:HelloWorld_Build1/steps/RUNNER_23 --data @rest_create_step.xml --header "Content-Type: application/xml"


Your .xml file looks correctly.

0
Comment actions Permalink

Thanks for the reply. That clears up which method should be used where/when. However, I still get errors when using POST to create a new step and I get a failure if I attempt to change any values or names in a PUT.
The error I get is:

Error has occurred during request processing (Conflict).
Error: jetbrains.buildServer.server.rest.errors.InvalidStateException: Update failed
Cannot process this request at this time. Repeat later.

So definitely making some small form of progress. Any other advice?


error when using POST to create a new step is:

Error has occurred during request processing (Internal Server Error).
Error: java.lang.RuntimeException: java.lang.NullPointerException, caused by: java.lang.NullPointerException
Error occurred while processing this request.

0
Comment actions Permalink

Could you please attach teamcity-rest.log file?

0
Comment actions Permalink

here is the relevant information from the log(the rest is just repeats of these errors with diff timestamps):

[2014-08-27 10:18:46,348]   WARN [-nio-80-exec-10] - est.jersey.ExceptionMapperUtil - Error has occurred during request processing (Conflict). Error: jetbrains.buildServer.server.rest.errors.InvalidStateException: Update failed. Cannot process this request at this time. Repeat later. Request: PUT '/httpAuth/app/rest/buildTypes/id:Testing_project_branch/steps/RUNNER_33', from client 192.168.1.115:54082, authenticated as 'btucker' {id=3}.
[2014-08-27 10:29:18,217]   WARN [p-nio-80-exec-8] - est.jersey.ExceptionMapperUtil - Error has occurred during request processing (Internal Server Error). Error: java.lang.RuntimeException: java.lang.NullPointerException, caused by: java.lang.NullPointerException. Error occurred while processing this request. Request: POST '/httpAuth/app/rest/buildTypes/id:Testing_project_branch/steps', from client 192.168.1.115:54326, authenticated as 'btucker' {id=3}.
java.lang.RuntimeException: java.lang.NullPointerException
at jetbrains.buildServer.serverSide.crypt.EncryptUtil.scrambleValue(EncryptUtil.java:148)
at jetbrains.buildServer.serverSide.crypt.EncryptUtil.scramble(EncryptUtil.java:158)
at jetbrains.buildServer.util.XmlUtil.writeParameter(XmlUtil.java:97)
at jetbrains.buildServer.util.XmlUtil.writeParameters(XmlUtil.java:142)
at jetbrains.buildServer.serverSide.impl.xml.XmlBaseExternalizer.addParametersElement(XmlBaseExternalizer.java:9)
at jetbrains.buildServer.serverSide.impl.xml.build.XmlBuildRunnersExternalizer.writeSettings(XmlBuildRunnersExternalizer.java:10)
at jetbrains.buildServer.serverSide.impl.xml.build.XmlBuildRunnersExternalizer.writeSettings(XmlBuildRunnersExternalizer.java:6)
at jetbrains.buildServer.serverSide.impl.xml.XmlBuildSettingsWriter.writeSettingsTo(XmlBuildSettingsWriter.java:6)
at jetbrains.buildServer.serverSide.impl.xml.BuildTypeXmlProducer.produceXmlElement(BuildTypeXmlProducer.java:7)
at jetbrains.buildServer.serverSide.impl.xml.BuildTypeXmlProducer.produceXmlElement(BuildTypeXmlProducer.java:6)
at jetbrains.buildServer.serverSide.impl.projects.ConfigurationEntityPersisters.persistElement(ConfigurationEntityPersisters.java:13)
at jetbrains.buildServer.serverSide.impl.projects.ConfigurationPersister.saveEntity(ConfigurationPersister.java:46)
at jetbrains.buildServer.serverSide.impl.BaseBuildTypeIdentity.doPersist(BaseBuildTypeIdentity.java:62)
at jetbrains.buildServer.serverSide.impl.BuildTypeImpl.persistInternal(BuildTypeImpl.java:630)
at jetbrains.buildServer.serverSide.impl.BaseBuildTypeIdentity$2.run(BaseBuildTypeIdentity.java)
at jetbrains.buildServer.configuration.ChangeObserver.runActionWithDisabledObserver(ChangeObserver.java:176)
at jetbrains.buildServer.serverSide.impl.projects.ProjectsWatcher.executeFSOperation(ProjectsWatcher.java:13)
at jetbrains.buildServer.serverSide.impl.BaseBuildTypeIdentity.persist(BaseBuildTypeIdentity.java:61)
at jetbrains.buildServer.server.rest.request.BuildTypeRequest.addStep(BuildTypeRequest.java:579)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.doFilter(ServletContainer.java:910)
at com.sun.jersey.spi.container.servlet.ServletContainer.doFilter(ServletContainer.java:858)
at jetbrains.buildServer.server.rest.APIController$3.apply(APIController.java:416)
at jetbrains.buildServer.server.rest.APIController$3.apply(APIController.java:402)
at jetbrains.buildServer.util.Util.doUnderContextClassLoader(Util.java:68)
at jetbrains.buildServer.server.rest.APIController.doHandle(APIController.java:402)
at jetbrains.buildServer.controllers.BaseController.handleRequestInternal(BaseController.java:75)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at jetbrains.buildServer.maintenance.TeamCityDispatcherServlet.service(TeamCityDispatcherServlet.java:28)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at jetbrains.buildServer.web.DependencyParametersCalculationContextFilter.doFilter(DependencyParametersCalculationContextFilter.java:4)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at jetbrains.buildServer.web.DisableSessionIdFromUrlFilter.doFilter(DisableSessionIdFromUrlFilter.java:3)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at jetbrains.buildServer.web.DiagnosticFilter.doFilter(DiagnosticFilter.java:48)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1721)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
at jetbrains.buildServer.serverSide.crypt.EncryptUtil.scrambleValue(EncryptUtil.java:146)
... 79 more
[2014-08-27 10:41:37,011]   INFO [14-08-27 10:41)] - rver.server.rest.APIController - Listening for paths [/app/rest, /app/rest/latest, /app/rest/8.0, /app/rest/8.1, /api] in plugin 'rest-api'

0
Comment actions Permalink

Ok so it turns out it DOES actually work but it throws errors. So the intial errors were due to me attmpting to change values that were based on a template and could not be changed in that build. I switched the ID to the template and it did actually allow me to change them. It still threw the same error responses even though it changed the values. The other problem is that the errors popping seemed to cause instability in the UI.

"Cannot access server"
"Document ID is NULL"

are some examples of errors that were thrown in the UI after I ran those commands. It looks like we dont need to alter the build steps in the configuration after all so it works out but these errors are troubling.

0
Comment actions Permalink

It is not possible to change build steps in configurations created from template both from UI and also from REST API.
I was able to reproduce the issue and found out that issue appears if API key field is empty. To prevent it please fill all required field. I've created an issue, please watch and vote for it.

0

Please sign in to leave a comment.