- Plugins.jetbrains.com › Plugin › 9042-python-runnerPython Runner - TeamCity Plugin | Marketplace
- Www.youtube.com › WatchNew In TeamCity 2020.2: Python Build Runner - YouTube
- Www.jetbrains.com › Help › TeamcityBuild Runner | TeamCity On-Premises
- Conditionally Execute A TeamCity Build Step
- How To Run A Python Script On Teamcity 10 - Stack Overflow
- Teamcity Python Runner Tutorial
Dec 16, 2020 Run your Python builds inside a Docker container. Use Kotlin DSL to configure your Python build steps. In addition, the Python runner integrates tightly with TeamCity just like all other TeamCity runners. You can track changes, analyze failures, assign investigations, and use any of the TeamCity features that you know and love. There is a Nose plugin that automatically detects when tests are being run from inside the TeamCity. This conveniently captures test results and communicates them with TeamCity. With this recipe, we will explore how to setup a CI job inside TeamCity that runs our tests and then manually invokes that job. I've authored this plugin in 2011 in spite of the day for running python scripts without problems of locating Python binaries on different platforms. However, that times have changed, and now I don't support this plugin. TeamCity since the version 2020.2 has a new bundled Python Runner that supports also virtual env, test reporting, etc.
Configuring TeamCity to run Python tests when scheduled. TeamCity can be configured to invoke our test suite and collect results in a scheduled interval. These steps will prepare us for this recipe by starting up TeamCity and having some code ready for testing. Dec 16, 2020 TeamCity 2020.2 comes with first-class native Python Support, and you no longer need to use a third-party plugin to build your Python projects. It supports all popular Python build workflows: Run files, modules, or custom scripts. Execute pytests or unittests. Run linters, like flake8 or pylint. Use virtual environments, like virtualenv or pipenv.
Latest versionReleased:
Use the TeamCity REST API from Python
Project description
PyTeamCity
Python interface to the RESTAPI ofTeamCity
New API work-in-progress
Note that I am working on a new API currently calledpyteamcity.future(initially added in#37).
Goal here is to create a brand new API that is much more flexible and tohave nicer code that is easier to work with. The old code encouragesadding a zillion methods for different ways of filtering. The new codehas an API with a smaller number of methods that are more consistent andmore flexible in terms of filtering. It is modeled after the Django ORMAPI.
There’s no formal docs for this API yet, but you should be able tofigure out how to use it by looking at the unittests.
I am probably not going to merge PRs that add things to the old API,because I see the new API as the future. I of course am very interestedin PRs that add things to the new API!
Examples
Connect to server
or specify no parameters and it will read settings from environmentvariables:
- TEAMCITY_USER
- TEAMCITY_PASSWORD
- TEAMCITY_HOST
- TEAMCITY_PORT (Defaults to 80 if not set)
Getting data
You can also look atsample.pyortest_legacy.py
Acknowledgements
This is a heavily-modified fork ofhttps://github.com/yotamoron/teamcity-python-rest-client so many thanksare due to Yotam Oron
Changes
0.1.1 (2016-11-09)
Project details
Release historyRelease notifications | RSS feed
0.1.1
0.1.0
0.0.1
0.0.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size pyteamcity-0.1.1-py2-none-any.whl (12.5 kB) | File type Wheel | Python version 2.7 | Upload date | Hashes |
Filename, size pyteamcity-0.1.1.tar.gz (35.0 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for pyteamcity-0.1.1-py2-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | 43a5c91e62590259321dec37cfd0dc297905e92d9d2026030a016acf3d0e8cf7 |
MD5 | df1d124c1bbddb3af017cbae5ae657bd |
BLAKE2-256 | f3ccc4e598e5c1a9250ec7088c239732bb4ac195f0439336f6b55389286f179e |
Plugins.jetbrains.com › Plugin › 9042-python-runnerPython Runner - TeamCity Plugin | Marketplace
Hashes for pyteamcity-0.1.1.tar.gz
Www.youtube.com › WatchNew In TeamCity 2020.2: Python Build Runner - YouTube
Algorithm | Hash digest |
---|---|
SHA256 | 3d9f97fff7f397f2c2484acd5acda7bb48681ec1ff9ed80443a7c374613b0fe1 |
MD5 | 7aa97fd86a151d3243ed1e31f79852cd |
BLAKE2-256 | 075b18104c49d8bb77a8f4ddd80822b223edbbd8e49ffcf539018b686b6b6e4f |
At Bazaarvoice, we use TeamCity for continuous integration testing. This has proved immensely useful for most of our Java projects, however as I am developing a Python application, I wanted to see if I could get TeamCity to run testing on my program. I already had a set of unit tests with pretty good code coverage, running fairly fast on my dev machine, so this was mainly an exercise to keep myself honest and track mistakes. No longer could I conveniently “forget” to run the tests before deploying, I want publicly fail within moments of pushing buggy code to master!
While proper unit testing is a topic covered elsewhere in far more detail and with far more expertise than I can provide, I want to share one tidbit that I have found to be the most important moment of “oh, now I get it…” as I’ve been learning how to properly design unit testing. Anytime something breaks, whether it’s in production, QA, or on your dev machine, immediately make sure there’s a corresponding unit test that breaks as well. If there isn’t, write one before fixing the bug. That way you’re sure it won’t happen again. I won’t overly evangelize unit testing, as I’ve been on teams who use it as a crutch, but with this one rule you can save yourself hours fixing bugs you’ve already fixed.
Anyway, as it turns out, JetBrains has already released a module called teamcity-messages, available via easy_install
or pip
. This module provides hooks for the unittest
, nose
, and py.test
unit testing frameworks in Python. I’m simply using unittest
, though I imagine working with the other two is similarly easy. The module is designed to be able to detect whether or not the test is being run from TeamCity, and if so, format the output in a way that TeamCity can immediately report and track tests as they run. When I started my project and unit tests took five seconds to run, there wasn’t much point, but now that unit testing takes a minute or so it can be helpful. For some of our larger projects which take an hour or more to run the full test suite, it’s critical to see failures immediately.
Adding teamcity-messages to your tests
Using unittest
with tests split into multiple modules can be fairly boilerplate - have one testing script that uses unittest.defaultTestLoader
, then use unittest.TextTestRunner
to run the loaded suite of tests. teamcity-messages
plays perfectly into that, as all you need to adjust is what runner you use. Here’s my current code:
The only change from when I originally wrote the test file was checking to see if we were running under TeamCity, and loading the appropriate test runner. Now, the testing script will run all my tests on both my development machine and TeamCity. No adjustments were needed to any of the tests themselves.
Getting your agents running
Now that we’ve got our tests reporting to TeamCity when they are actually run there, lets get them running there. Turns out, this was actually the harder part of the operation. The first step was setting up the VCS root to read from the project on GitHub. This was simple to do from the build configuration settings, and we were able to leave most options at default. Then, in the ‘Build Triggering’ section, set up a trigger to build after every VCS change. That is, anytime a change to the branch TeamCity is listening to (default is master, but can be changed), it’ll perform the build steps. This means you should probably have developers pushing code directly to their own branches, and only push to master when it’s ready for public consumption - even if that doesn’t mean a release.
The build steps, too, were fairly simple. In addition to my Python unittest
script, I also use Grunt to lint my code. Adding these was as simple as adding two Command Line build runners: python26 testing.py
for the Python tests, and node_modules/grunt/bin/grunt
to run Grunt. Python26 was selected due to version conflicts on the build agents. I ran Grunt that way so it didn’t have to actually be installed, it could be in the source code.
However, this was pretty much the end of the simple tasks. Turns out, it isn’t perfectly straightforward to install python requirements onto a build agent. For our purposes we ended up installing the requirements on all the agents manually, however to keep this working in the future we’d have to add this step to the build agent deployment script. Additionally, once I added some dependencies to AWS services, transferring the IAM credentials to the testing boxes proved to be a challenge we never ended up surmounting before my DevOps engineer working on the project shifted off, and I needed to continue myself.
In Conclusion
Unfortunately, I’m somewhat sad to say (given how much work went into it) that my TeamCity build configuration is paused with the solemn message “Discontinued until I figure out how to make it run without errors.” I still run the same exact tests locally, and as I am the only engineer on the project I have no pressing need to ensure all code is tested as it is checked in. In the future, there’s a couple things I’d like to do to fix things, however.
I believe I can install the Python modules to the agents as local modules, rather than global installations. I always use virtualenv, so my requirements.txt
stays up to date. Since the build runners don’t have root permissions, I can’t install packages globally. Neither can I easily set up virtual environments on the build agents. I believe I can install them to the source directory with some variation of pip install --install-option='--prefix=$PREFIX_PATH' package_name
but I haven’t gotten into testing this.
As for the AWS credentials, I’m not sure how I’ll get them into the build agents. I’m sure other teams have done something so once I get the packages installing correctly, I will ask around. Another alternate is simply mock out all AWS services. For some functions like sending email this makes the most sense anyway.
Hopefully soon, I’ll be back up and running with TeamCity and will make a new post about the changes. Until then, I’ll dutifully maintain my unit testing locally in the hopes it may become automated again in the future.