GithubHelp home page GithubHelp logo

microsoft / azure-devops-python-samples Goto Github PK

View Code? Open in Web Editor NEW
103.0 20.0 82.0 36 KB

Python samples for interacting with and managing Azure DevOps

Home Page: https://azure.microsoft.com/services/devops/

License: MIT License

Jupyter Notebook 13.37% Python 86.63%
python vsts api samples

azure-devops-python-samples's Introduction

Python samples for Azure DevOps

This repository contains Python samples that show how to integrate with Azure DevOps and Team Foundation Server (TFS) using the Azure DevOps Python API.

As of January 2021, we're no longer actively maintaining this repo. Feel free to continue using it for inspiration or examples. We won't be updating or adding any samples, though.

Explore

Samples are organized by "area" (service) and "resource" within the samples package. Each sample module shows various ways for interacting with Azure DevOps and TFS. Resources may have multiple samples, since there are often multiple ways to query for a given resource.

Installation

  1. Clone this repository and cd into it

  2. Create a virtual environment (python3 -m venv env && . env/bin/activate && pip install -r requirements.txt)

Now you can run runner.py with no arguments to see available options.

Run the samples - command line

VERY IMPORTANT: some samples are destructive! It is recommended that you run these samples against a test organization.

  1. Get a personal access token.

  2. Store the PAT and organization URL you'll be running samples against (note: some samples are destructive, so use a test organization):

    • python runner.py config url --set-to https://dev.azure.com/fabrikam
    • python runner.py config pat --set-to ABC123
    • If you don't want your PAT persisted to a file, you can put it in an environment variable called AZURE_DEVOPS_PAT instead
  3. Run python runner.py run {area} {resource} with the 2 required arguments:

    • {area}: API area (currently core, git, and work_item_tracking) to run the client samples for. Use all to include all areas.
    • {resource}: API resource to run the client samples for. Use all to include all resources.
    • You can optionally pass --url {url} to override your configured URL

Examples

Run all samples

python runner.py run all all

Run all work item tracking samples

python runner.py run work_item_tracking all

Run all Git pull request samples

python runner.py run git pullrequests

Run all Git samples against a different URL than the one configured; in this case, a TFS on-premises collection

python runner.py run git all --url https://mytfs:8080/tfs/testcollection

Save request and response data to a JSON file

To persist the HTTP request/response as JSON for each client sample method that is run, set the --output-path {value} argument. For example:

python runner.py run all all --output-path ~/temp/http-output

This creates a folder for each area, a folder for each resource under the area folder, and a file for each client sample method that was run. The name of the JSON file is determined by the name of the client sample method. For example:

|-- temp
    |-- http-output
        |-- git
            |-- refs
                |-- get_refs.json
                |-- ...
            |-- repositories
                |-- get_repositories.json
                |-- ...

Note: certain HTTP headers like Authorization are removed for security/privacy purposes.

See what samples are available

You can run runner.py list to see what sample areas and resources are available.

Run the samples - Jupyter notebook

We also provide a Jupyter notebook for running the samples. You'll get a web browser where you can enter URL, authentication token, and choose which samples you wish to run.

  1. Clone this repository and cd into it

  2. Create a virtual environment (python3 -m venv env && . env/bin/activate && pip install -r requirements.jupyter.txt)

  3. Get a personal access token.

  4. Run jupyter notebook. In the resulting web browser, click API Samples.ipynb.

  5. Click Run in the top cell. Scroll down and you'll see a form where you can enter your organization or TFS collection URL, PAT, and choose which samples to run.

IMPORTANT: some samples are destructive. It is recommended that you first run the samples against a test account.

Contribute

This repo is no longer maintained, and therefore is not accepting new contributions.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

See detailed instructions on how to contribute a sample.

azure-devops-python-samples's People

Contributors

microsoftopensource avatar msftgits avatar vtbassmatt avatar willsmythe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-devops-python-samples's Issues

Setting up config for the first time gets misleading warning

Screen Shot 2020-04-23 at 8 41 38 PM

Logging a tiny usability bug:

Getting the above output when I was setting the config. Specifically

The default filename has changed. You may need to rename
vsts-runner-config.json
to
azure-devops-runner-config.json

That warning msg will show up for everybody who's setting up the config for the first time, since azure-devops-runner-config.json has yet been created, which is misleading.

Example of function `create_attachment`

Hi (and Happy New Year),

I am working on improving the examples for create_attachment functions and related functionalities (e.g. add attachment to step or retrieving list of attachments for a Test Case).

Could you tell me actually what is the stream for the create_attachment function?

    def create_attachment(self, upload_stream, project=None, file_name=None, upload_type=None, area_path=None):
        """CreateAttachment.
        Uploads an attachment.
        :param object upload_stream: Stream to upload
        ...
        """

I tried both solutions below but none seems to work:

with open('./smiley.png', "rb") as f:
    binary_content = bytes(f.read())
attachment = client_wit.create_attachment(binary_content, project, 'smiley.png')
attachment = client_wit.create_attachment("Hello my friend", project, 'test6.txt')

(this solution creates a text file but it contains the double quotes in the text)

Thanks

Samples are rather limited

Hi,

The main API is great and it is nice to have some sample code. However, I have just found 2 examples for workitems and 2 for Git.

Am I missing something?

Also, I cannot find anything on how to use WIQL queries with the API.

Thanks

Azur DevOps throws ValueError: Could not get version for Chrome with this command: reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version

Hi,

Agent pool : Windows
Installed Chrome Version : 85.0.1483.103

When i run the Pytests, it throws "ValueError: Could not get version for Chrome with this command: reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version "

Dev Ops has confirmed Windows agent has Chrome.

We are stuck here,cannot move forward.

Could some one please shed the lights!

Locally, works fine

2020-09-09T17:11:18.2185128Z ##[section]Starting: Run smoke_test copy
2020-09-09T17:11:18.2391733Z ==============================================================================
2020-09-09T17:11:18.2392103Z Task : Command line
2020-09-09T17:11:18.2392268Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2020-09-09T17:11:18.2392446Z Version : 2.164.2
2020-09-09T17:11:18.2392574Z Author : Microsoft Corporation
2020-09-09T17:11:18.2392757Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2020-09-09T17:11:18.2392882Z ==============================================================================
2020-09-09T17:11:19.3860400Z Generating script.
2020-09-09T17:11:19.4228320Z ========================== Starting Command Output ===========================
2020-09-09T17:11:19.4483483Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "F:\XXX-vsts-agent-2_work_temp\f3ac2905-7c4a-40ef-a58b-c37a21431ffc.cmd""
2020-09-09T17:11:20.4105411Z Package Version
2020-09-09T17:11:20.4106029Z --------------------- ---------
2020-09-09T17:11:20.4106901Z ansi2html 1.5.2
2020-09-09T17:11:20.4108199Z apipkg 1.5
2020-09-09T17:11:20.4108775Z atomicwrites 1.4.0
2020-09-09T17:11:20.4110321Z attrs 20.2.0
2020-09-09T17:11:20.4110860Z certifi 2020.6.20
2020-09-09T17:11:20.4112407Z chardet 3.0.4
2020-09-09T17:11:20.4112925Z colorama 0.4.3
2020-09-09T17:11:20.4114389Z configparser 5.0.0
2020-09-09T17:11:20.4114959Z crayons 0.4.0
2020-09-09T17:11:20.4116475Z docutils 0.16
2020-09-09T17:11:20.4116853Z execnet 1.7.1
2020-09-09T17:11:20.4118407Z htmlmin 0.1.12
2020-09-09T17:11:20.4118897Z idna 2.10
2020-09-09T17:11:20.4120404Z iniconfig 1.0.1
2020-09-09T17:11:20.4120942Z Jinja2 2.11.2
2020-09-09T17:11:20.4122443Z jsonschema 3.2.0
2020-09-09T17:11:20.4122990Z MarkupSafe 1.1.1
2020-09-09T17:11:20.4124497Z more-itertools 8.5.0
2020-09-09T17:11:20.4125054Z msgpack 1.0.0
2020-09-09T17:11:20.4126496Z numpy 1.19.1
2020-09-09T17:11:20.4127190Z packaging 20.4
2020-09-09T17:11:20.4128715Z pandas 1.1.2
2020-09-09T17:11:20.4129630Z pip 20.1.1
2020-09-09T17:11:20.4131451Z pluggy 0.13.1
2020-09-09T17:11:20.4132120Z py 1.9.0
2020-09-09T17:11:20.4132672Z pyparsing 2.4.7
2020-09-09T17:11:20.4133276Z pyrsistent 0.16.0
2020-09-09T17:11:20.4134242Z pytest 6.0.1
2020-09-09T17:11:20.4134770Z pytest-azurepipelines 0.8.0
2020-09-09T17:11:20.4160614Z pytest-colordots 1.1
2020-09-09T17:11:20.4161603Z pytest-forked 1.3.0
2020-09-09T17:11:20.4162070Z pytest-html 2.1.1
2020-09-09T17:11:20.4162463Z pytest-metadata 1.10.0
2020-09-09T17:11:20.4162873Z pytest-ordering 0.6
2020-09-09T17:11:20.4163243Z pytest-reporter 0.4.0
2020-09-09T17:11:20.4163626Z pytest-reporter-html1 0.7.0
2020-09-09T17:11:20.4163994Z pytest-xdist 2.1.0
2020-09-09T17:11:20.4164382Z python-dateutil 2.8.1
2020-09-09T17:11:20.4164765Z python-json-config 1.2.3
2020-09-09T17:11:20.4165133Z pytz 2020.1
2020-09-09T17:11:20.4165634Z requests 2.24.0
2020-09-09T17:11:20.4166026Z selenium 3.141.0
2020-09-09T17:11:20.4166703Z setuptools 47.1.0
2020-09-09T17:11:20.4167116Z six 1.15.0
2020-09-09T17:11:20.4167546Z substring 0.2
2020-09-09T17:11:20.4167958Z toml 0.10.1
2020-09-09T17:11:20.4168388Z urllib3 1.25.10
2020-09-09T17:11:20.4169418Z webdriver-manager 3.2.2
2020-09-09T17:11:20.4750689Z WARNING: You are using pip version 20.1.1; however, version 20.2.3 is available.
2020-09-09T17:11:20.4751236Z You should consider upgrading via the 'c:\program files (x86)\python38-32\python.exe -m pip install --upgrade pip' command.
2020-09-09T17:11:22.3209924Z ============================= test session starts =============================
2020-09-09T17:11:22.3212494Z platform win32 -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
2020-09-09T17:11:22.3361227Z rootdir: F:\xxxx-vsts-agent-2_work\18\s\Tests, configfile: pytest.ini
2020-09-09T17:11:22.3361685Z plugins: azurepipelines-0.8.0, colordots-1.1, forked-1.3.0, html-2.1.1, metadata-1.10.0, ordering-0.6, reporter-0.4.0, reporter-html1-0.7.0, xdist-2.1.0
2020-09-09T17:11:22.3415903Z gw0 I / gw1 I / gw2 I / gw3 I / gw4 I
2020-09-09T17:11:25.4888327Z collected 7 items / 1 deselected / 6 selected
2020-09-09T17:11:27.7173269Z gw0 [6] / gw1 [6] / gw2 [6] / gw3 [6] / gw4 [6]
2020-09-09T17:11:27.7173855Z
2020-09-09T17:11:29.9637114Z ##[error]12 test(s) failed, 6 test(s) collected.
2020-09-09T17:11:29.9644764Z Skipping uploading of coverage data.
2020-09-09T17:11:29.9645049Z
2020-09-09T17:11:29.9648336Z =================================== ERRORS ====================================
2020-09-09T17:11:29.9654309Z _ ERROR at setup of Test_PayrollAccountant.test_Employee_TC_For_Regular_Week_Wit_Allowance_Rejected_By_PA _
2020-09-09T17:11:29.9654900Z [gw4] win32 -- Python 3.8.5 c:\program files (x86)\python38-32\python.exe
2020-09-09T17:11:29.9655182Z
2020-09-09T17:11:29.9655477Z request = <SubRequest 'setup' for >
2020-09-09T17:11:29.9655716Z
2020-09-09T17:11:29.9655953Z @pytest.fixture()
2020-09-09T17:11:29.9656193Z def setup(request):
2020-09-09T17:11:29.9656433Z url = str(ReadConfig.getApplicationURL())
2020-09-09T17:11:29.9656691Z DefinedBrowser = ReadConfig.getBrowser()
2020-09-09T17:11:29.9656959Z global driver
2020-09-09T17:11:29.9657198Z if DefinedBrowser.lower() == "chrome":
2020-09-09T17:11:29.9657458Z # driver=webdriver.Chrome("./Configurations/Browser_Drivers/chromedriver.exe")
2020-09-09T17:11:29.9657729Z > driver = webdriver.Chrome(ChromeDriverManager().install())
2020-09-09T17:11:29.9657951Z
2020-09-09T17:11:29.9658196Z Tests\conftest.py:20:
2020-09-09T17:11:29.9658445Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2020-09-09T17:11:29.9658728Z C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Python\Python38\site-packages\webdriver_manager\chrome.py:23: in init
2020-09-09T17:11:29.9659005Z self.driver = ChromeDriver(name=name,
2020-09-09T17:11:29.9659263Z C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Python\Python38\site-packages\webdriver_manager\driver.py:54: in init
2020-09-09T17:11:29.9659536Z self.browser_version = chrome_version(chrome_type)
2020-09-09T17:11:29.9659799Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2020-09-09T17:11:29.9660034Z
2020-09-09T17:11:29.9660260Z browser_type = 'google-chrome'
2020-09-09T17:11:29.9660484Z
2020-09-09T17:11:29.9660725Z def chrome_version(browser_type=ChromeType.GOOGLE):
2020-09-09T17:11:29.9660964Z pattern = r'\d+.\d+.\d+'
2020-09-09T17:11:29.9661276Z
2020-09-09T17:11:29.9661529Z cmd_mapping = {
2020-09-09T17:11:29.9661779Z ChromeType.GOOGLE: {
2020-09-09T17:11:29.9662026Z OSType.LINUX: 'google-chrome --version || google-chrome-stable --version',
2020-09-09T17:11:29.9662302Z OSType.MAC: r'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version',
2020-09-09T17:11:29.9662579Z OSType.WIN: r'reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version'
2020-09-09T17:11:29.9662827Z },
2020-09-09T17:11:29.9663073Z ChromeType.CHROMIUM: {
2020-09-09T17:11:29.9663797Z OSType.LINUX: 'chromium --version || chromium-browser --version',
2020-09-09T17:11:29.9664095Z OSType.MAC: r'/Applications/Chromium.app/Contents/MacOS/Chromium --version',
2020-09-09T17:11:29.9665293Z OSType.WIN: r'reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" /v version'
2020-09-09T17:11:29.9665603Z },
2020-09-09T17:11:29.9665849Z ChromeType.MSEDGE: {
2020-09-09T17:11:29.9666118Z OSType.MAC: r'/Applications/Microsoft\ Edge.app/Contents/MacOS/Microsoft\ Edge --version',
2020-09-09T17:11:29.9666392Z OSType.WIN: r'reg query "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Edge\BLBeacon" /v version',
2020-09-09T17:11:29.9666646Z }
2020-09-09T17:11:29.9666886Z }
2020-09-09T17:11:29.9667218Z
2020-09-09T17:11:29.9667449Z cmd = cmd_mapping[browser_type][os_name()]
2020-09-09T17:11:29.9667680Z stdout = os.popen(cmd).read()
2020-09-09T17:11:29.9667924Z version = re.search(pattern, stdout)
2020-09-09T17:11:29.9668150Z if not version:
2020-09-09T17:11:29.9668391Z > raise ValueError(f'Could not get version for Chrome with this command: {cmd}')
2020-09-09T17:11:29.9668658Z E ValueError: Could not get version for Chrome with this command: reg query
"HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version
2020-09-09T17:11:29.9668917Z
2020-09-09T17:11:29.9669153Z C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Python\Python38\site-packages\webdriver_manager\utils.py:142: ValueError

Please see the below screenshots

image

image

image

image

Get test result for a specific test case

In .../samples/test.py, you have a function, def get_test_results(context):

This appears to get all of the test results for a given context. Is it possible to get the test result of a single test case?

There are no tests

The samples need a set of tests so that we can safely make runner/framework changes, and so we can run against new versions of the VSTS API.

Sample for create test run and update test run result for particular test-points

Firstly Thanks for you support and effort .

I am started understanding version 5.1. It bit difficult to understand method as there no sample for the most of method.
Request here is, Do we have any documentation on how to use method in packages. like (pandas or flask). ? If Yes Could you please share us that documentation link.
if no, Could you please help us on this to method and usages especially on "Test"

Add support of Azure DevOps version 5.0 / 5.1

Module vsts for VSTS / TFS has been replaced by azure-devops (https://github.com/Microsoft/azure-devops-python-api) with versions 5.0 and 5.1 of the API.

The code has been reworked; for example, the following:

from vsts.vss_connection import VssConnection
connection = VssConnection(base_url=team_instance, creds=credentials)
core_client = connection.get_client('vsts.core.v4_0.core_client.CoreClient')

has been replaced by:

from azure.devops.connection import Connection
connection = Connection(base_url=organization_url, creds=credentials)
core_client = connection.clients.get_core_client()

It should be considered to have both versions available in the example (and set via a variable in the configuration). Or at least the latest version.

this breaks at the first step

running the command python3 -m venv env && . env/bin/activate && pip install -r requirements.txt just wont go past. I have tried to break the command into parts. but then there is no correct path for env/bin/activate. the activate is in the Scripts folder. but running it from there gives another "deactivate { " error. can you provide resolution for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.