Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
TeamCity: Add NuGet package steps to trigger Octopus Deploy (#432)
Browse files Browse the repository at this point in the history
* Added NuGet package steps

* Add link to octopus ARC doc
  • Loading branch information
samiyaakhtar committed May 15, 2019
1 parent 4a5998f commit de96238
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions gitops/teamcity/ConnectToOctopus.md
Expand Up @@ -6,6 +6,40 @@ Make sure you already have a running CI pipeline in TeamCity and a CD pipeline i

## Trigger Octopus from TeamCity

There are two ways to trigger Octopus from TeamCity. The more direct method is to invoke the `octo.exe` CLI and use their `create-release` script to kick off a new release, and the other method is to create a NuGet package for the application and push it to the Octopus package repository. This second method is more preferable in cases where a NuGet package can be built from the source code, and does not involve any direct project triggers in Octopus from TeamCity. The following guide provices both options for achieving this.

### Trigger Octopus using NuGet package

For projects that use NuGet packages to build and push their applications, the following trigger to Octopus is the more preferred method. First we build the source code application, package it up into a NuGet application and publish it into the Octopus package repository. The steps below assume that your application code is already generating a NuGet package and that it is available to push.

Add a build step to the end of the other build steps, which would push the NuGet package:

![](./images/nuget_step.png)

Paste the following code and replace `Foo.App` with your app name:
```
chmod +x ./Octo
rm -rf AppArtifacts/
rm -rf Foo.App.*
./Octo push --package=$PACKAGE_NAME --server=$OCTO_SERVER --apiKey=$OCTO_API_KEY --replace-existing --space $OCTO_SPACE
```

This code assumes the following variables are defined as environment variables under Parameters:

- `PACKAGE_NAME`: The name of your .nupkg file
- `OCTO_SERVER`: The URL to your Octopus server
- `OCTO_API_KEY`: Obtain an API key for your Octopus server by going into your profile settings. It should be in the format `API-XXXXXXXXXXXXXXXXXX`
- `OCTO_SPACE`: The project space in which the release resides under. If it's under default, you may skip this parameter.

Make sure this build step executes after all other build steps are complete. Do a test run to see the logs from this build, and they should look something like below:

![](./images/nuget_logs.png)

Next, you've to setup Automatic Release Creation in Octopus, follow the guide [here](../octopus/ImageTagRelease.md#enable-automatic-release-creation-and-auto-deploy).

### Trigger Octopus by creating new explicit release

This guide sets a build step for triggering Octopus CD for an Image Tag Release pipeline that we set up for the GitOps workflow. It builds an ACR image and publishes it, then triggers Octopus Deploy with the tag of the newly built image.

Add a build step to the end of the integration steps, which would trigger Octopus CD. It should look like below:
Expand All @@ -28,7 +62,7 @@ echo "chmod +x ./Octo"
chmod +x ./Octo
echo "CREATING NEW RELEASE for $ACR_CONTAINER_TAG"
./Octo create-release --project $PROJECT_NAME --deployto $ENV_NAME --server $OCTO_SERVER --apiKey $OCTO_API_KEY --space $SPACE --variable "YAML_PATH_VALUE:$ACR_CONTAINER_TAG"
./Octo create-release --project $PROJECT_NAME --deployto $ENV_NAME --server $OCTO_SERVER --apiKey $OCTO_API_KEY --space $OCTO_SPACE --variable "YAML_PATH_VALUE:$ACR_CONTAINER_TAG"
```

This step assumes the following variables are set up in TeamCity:
Expand All @@ -38,7 +72,7 @@ This step assumes the following variables are set up in TeamCity:
- `ACR_CONTAINER_TAG`: In order to set an ACR tag that contains build number, branch name and commit hash, follow steps [here](./ImageTagRelease.md#creating-an-acr-container-tag-with-branch-name-commit-hash-and-build-number). Otherwise, If you would like to skip creating a complex ACR tag for simplicity, set this to any constant image tag which is stable in your ACR.
- `ENV_NAME`: This should be set to the environment you would like to create a release for. For example `DEV`.
- `PROJECT_NAME`: The name of the project you're creating a release for
- `SPACE`: The project space in which the release resides under. If it's under default, you may skip this parameter.
- `OCTO_SPACE`: The project space in which the release resides under. If it's under default, you may skip this parameter.

Make sure this build step executes after the ACR images are built in the pipeline. Do a test run to see the logs from ths build step, and they should look like something below:

Expand Down
Binary file added gitops/teamcity/images/nuget_logs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gitops/teamcity/images/nuget_step.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gitops/teamcity/images/trigger_octo_logs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit de96238

Please sign in to comment.