teamcity-connector

A client that will connect to teamcity API to perform all functions for maintaining projects

Usage no npm install needed!

<script type="module">
  import teamcityConnector from 'https://cdn.skypack.dev/teamcity-connector';
</script>

README

teamcity-connector

A client that will connect to teamcity API to perform all functions for maintaining projects

Usage

Creating the connector

Create a new TeamcityConnector

let connector = new TeamcityConnector('http://localhost:8111', 'user', 'password');

Projects

All project work is located under the Project property of the TeamcityConnector

Get a project

To retrieve an existing project you can search for the project by name

let projectDetails = connector.project.get({name: 'Project Name'});

Create a Project

To create a project you just need the name of the project to create and the id of the parent project. If this is a new project created from scratch you do not need to provide a parent project anf the new project will be placed under the root.

let result = connector.project.create({name: 'My Subproject', parent: 'Parent Project Name'});

BuildTypes

The buildTypes are the definitions used when creating a TeamcityBuild, you will need to create this after you create your project

Get A BuildType

To locate a BuildType you will need to know its name and the name of the project that it belongs to

let buildTypeDetail = connector.buildtype.get({name: 'BuildType Name', project: 'Project Name'});

Create a new BuildType

Creating a basic BuildType can be done manually or you can use a template, to use the template just provide the Id of the template you wish to use. If you leave the template Id empty then no template will be used you can substitute the project name for projectId

let result = connector.buildtype.create({name: 'My Buildtype', projectName: 'Project Name', template: 'TemplateId'});

let result = connector.buildtype.create({name: 'My Buildtype', projectId: 'Project_Id', template: 'TemplateId'});

Adding Parameters

When you have created your BuildType you will want to amend the Parameters for your deployments

let result = connector.buildtype.addParameters({
  buildTypeId: 'build_type_id',
  parameters: [
    { name: parameter1, value: value1 },
    { name: parameter2: value: value2 }
  ]
})

VcsRoot

All builds needs to get their source form somewhere, so provide an VcsRoot

Get an existing VcsRoot

let vcsrootDetail = connector.VcsRoot().get({name: 'VcsRoot name'});

Create a VcsRoot

Creating a VcsRoot is more involved,

let result = connector.vcsroot.create({
  name: 'VcsRoot Name',
  projectName: 'Project Name',
  projectId: 'ProjectId',
  url: 'Repository Url',
  branch: 'Branch name',
  vcsType: 'Type name'    
});

Adding Properties

When you have created your Vcs Root you will want to amend the Properties

let result = connector.vcsroot.addProperties({
  name: 'VcsRoot Name',
  properties: [
    { name: property1, value: value1 },
    { name: property2: value: value2 }
  ]
})

This is a lot of options but lets go through them

  • name - this is the name of the VcsRoot and is Required
  • projectName - the name of the project to create the VcsRoot in
  • projectId - the Id of the project of the project, you must have either this or the project name specified
  • url - the url to the Repository, this is mandatory
  • branch - the name of the branch to use
  • vcsType - the type of VcsRoot to create [jetbrains.get|perforce|svn|tfs]

Testing

Docker

To test the library you can set up a new TeamCity server using JetBrains Docker container

docker pull jetbrains/teamcity-server
docker run -p 8111:8111 -d jetbrains/teamcity-server