class Danger::TeamCity

### CI Setup

You need to go to your project settings. Then depending on the type of your build settings, you may need to add a new build step for Danger. You want to be able to run the command ‘bundle exec danger`, so the “Simple Command Runner” should be all you need to do that.

### Token + Environment Setup

#### GitHub

As this is self-hosted, you will need to add the ‘DANGER_GITHUB_API_TOKEN` to your build user’s ENV. The alternative is to pass in the token as a prefix to the command ‘DANGER_GITHUB_API_TOKEN=“123” bundle exec danger`.

However, you will need to find a way to add the environment vars: ‘GITHUB_REPO_SLUG`, `GITHUB_PULL_REQUEST_ID` and `GITHUB_REPO_URL`. These are not added by default. You can manually add `GITHUB_REPO_SLUG` and `GITHUB_REPO_URL`

as build parameters or by exporting them inside your Simple Command Runner.

As for ‘GITHUB_PULL_REQUEST_ID`, TeamCity provides the `%teamcity.build.branch%` variable which is in the format `PR_NUMBER/merge`. You can slice the Pull Request ID out by doing the following:

“‘sh branch=“%teamcity.build.branch%” export GITHUB_PULL_REQUEST_ID=(${branch//// }) “`

Or if you are using the pull request feature you can set an environment parameter called ‘GITHUB_PULL_REQUEST_ID` to the value of: `%teamcity.pullRequest.number`

#### GitLab

As this is self-hosted, you will need to add the ‘DANGER_GITLAB_API_TOKEN` to your build user’s ENV. The alternative is to pass in the token as a prefix to the command ‘DANGER_GITLAB_API_TOKEN=“123” bundle exec danger`.

However, you will need to find a way to add the environment vars: ‘GITLAB_REPO_SLUG`, `GITLAB_PULL_REQUEST_ID` and `GITLAB_REPO_URL`. These are not added by default. You could do this via the GitLab API potentially.

We would love some advice on improving this setup.

#### BitBucket Cloud

You will need to add the following environment variables as build parameters or by exporting them inside your Simple Command Runner.

or

You will also need to set the ‘BITBUCKET_BRANCH_NAME` environment variable. TeamCity provides `%teamcity.build.branch%`, which you can use at the top of your Simple Command Runner:

“‘sh export BITBUCKET_BRANCH_NAME=“%teamcity.build.branch%” “`

#### BitBucket Server

You will need to add the following environment variables as build parameters or by exporting them inside your Simple Command Runner.