restteamcity-7.0

Creating Build Configuration via REST in Teamcity


Is it possible to create a new build configuration for an existing project via REST api(POST method) in Teamcity?
If so, how to create? (some guidelines )

Thanks


Solution

  • It's for sure possible on 8.x, haven't the need to care about early versions.

    Here's a really simple python snippet that will copy an existing build config into a given project using this as a guide http://confluence.jetbrains.com/display/TCD8/REST+API#RESTAPI-BuildConfigurationAndTemplateSettings.

    import requests
    
    xml =  """<newBuildTypeDescription name='NewBuildConfigName'
              sourceBuildTypeLocator='ExistingBuildConfigNameThatYouWantToCopy'
              copyAllAssociatedSettings='true' shareVCSRoots='false'/>
           """
    headers = {'Content-Type': 'application/xml'} # set what your server accepts
    
    print requests.post('http://YOURTEAMCITYWEBADDRESS:YOURTEAMCITYPORT/httpAuth/app/rest/projects/id:PROJECTIDWHERENEWBUILDCONFIGSHOULDBECREATED/buildTypes', data=xml, headers=headers, auth=('TeamCityUserName','TeamCityPassword')).text