Search code examples
githubdeploymentteamcityartifact

How to deploy artifact to github releases using TeamCity


I configured TeamCity to pull and build my github repo. Than it creates .zip artifact with files that are in "bin/Debug" folder. After that I want it to create a new tag with build number and push it to github releases, but don't have any idea how to do it.


Solution

  • After research i finally found the answer.

    1. Install github-release on the TeamCity build agent server(s). To install github-release get the latest release and extract .exe file somewhere on drive (In my case C:\Program Files (x86)\github-release\bin\windows\amd64)
    2. Generate new security access token on github.
    3. Create artifact after build. To do it go to your build configuration and set ArtifactPaths to MyProjectName\bin\Debug => DependentArtifact.zip
    4. Create second build configuration (Not build step) with "Deploy" Name.
    5. Add new trigger to Deploy configuration. Triggers => Add new Trigger => Finish Build Trigger => Set build configuration to your first build name and enable "Trigger after successful build only " checkbox
    6. Add dependent artifact to Deploy build configuration: Dependencies => Add new artifactDependency. Set Depend On = to your first build configuration. Get artifacts from = Latest successful build. Artifact Rules = DependentArtifact.zip
    7. Add new build step to Deploy: Build Steps => Add build step => CommandLine and paste following script to custom script field:

      [PathToYourRepo] git tag Release-v0.%build.number%
      [PathToYourRepo] git push
      [PathToYourRepo] git push --tags

      [PathToGithubReleaseExe] release --security-token [YourSecurityToken] --user [YourGithubUserName] --repo [YourRepoName] --tag Release-v0.%build.number%

      [PathToGithubReleaseExe] upload --security-token [YourSecurityToken] --user [YourGithubUserName] --repo [YourRepoName] --tag Release-v0.%build.number% --name Release-v0.%build.number%.zip --file DependentArtifact.zip

    And that's it! Maybe there is a simpler way to do it, but I haven't found it.