tfx-cli Documentation

repository·master·Indexed 18 days ago

https://github.com/microsoft/tfs-cli

A Node.js-based command-line utility for interacting with Microsoft Team Foundation Server (TFS) and Azure DevOps Services. It provides command sets to manage builds, build tasks, extensions, and work items. The CLI supports Personal Access Tokens and basic authentication, offers flexible output formats (friendly, JSON, clipboard, or file), and includes a settings cache to save command options.

Tokens
7.8K
Snippets
38
Records
47
Agent score
63%

What's inside tfx-cli

  1. Use a Manifest JS file for dynamic builds

    master

    To differentiate between development and production builds, use the --manifest-js option. You must provide a Node.js CommonJS module that exports a function. This function receives an env object (populated by the --env flag) and must return a manifest JSON object.

    This allows you to programmatically change IDs, names, or properties like baseUri based on the environment.

    module.exports = (env) => {
    	let [idPostfix, namePostfix] = (env.mode == "development") ? ["-dev", " [DEV]"] : ["", ""];
    
    	let manifest = {
    		manifestVersion: 1,
    		id: `myextensionidentifier${idPostfix}`,
    		name: `My Great Extension${namePostfix}`,
    		...
    		contributions: [
    			{
    				id: "mywidgetidentifier",
    				properties: {
    					name: `Super Widget${namePostfix}`,
    					...
    				},
    				...
    			}
    		]
    	}
    
    	if (env.mode == 'development') {
    		manifest.baseUri = "https://localhost:3000";
    	}
    
    	return manifest;
    }
  2. Delete a build task

    master

    To remove a task from the server, use the tfx build tasks delete command with the --task-id flag. You can find the required ID by running the list command first.

    ~/$ tfx build tasks delete --task-id 4e131b60-5532-4362-95b6-7c67d9841b4f
    Copyright Microsoft Corporation
    
    task: 4e131b60-5532-4362-95b6-7c67d9841b4f deleted successfully!
  3. Build tfx-cli from source

    master

    To develop or build the project from source:

    1. Install dependencies:
      npm install
    2. Build the project:
      npm run build
      This compiles TypeScript files from app/ to JavaScript in _build/.
    3. Clean build artifacts (optional):
      npm run clean
    npm run build
  4. Authenticate for Work Item commands

    master

    To use work item commands with Team Foundation Server (TFS), you must login using the specific collection URL. For Visual Studio Team Services (VSTS), your standard account URL is sufficient.

    TFS Login Example: tfx login --service-url http://myServer/DefaultCollection

    VSTS Login Example: tfx login --service-url https://myAccount.VisualStudio.com

    tfx login --service-url http://myServer/DefaultCollection
  5. Login to TFS using Basic Authentication

    master

    Use the tfx login command with the --auth-type basic flag to authenticate against an on-premises TFS server.

    Authentication Workflow:

    1. Run tfx login --auth-type basic.
    2. Service URL: Provide the service URL. For TFS on-prem, if the server name is part of the URL, you must use the Fully Qualified Domain Name (FQDN), e.g., servername.domain.local.
    3. Username: Use the format domain\user (e.g., fabrikam\peter). If using a workgroup machine, use machinename\username.
    4. Password: Enter the password for the specified user.

    Once logged in, you can proceed to use any other tfx commands.

    tfx login --auth-type basic
  6. Install local changes globally for verification

    master

    To verify your local changes as a user would after installing from npm, you can install the built product globally by pointing npm install to the local directory instead of a package name.

    After running npm run build, navigate to the _build directory and run:

    sudo npm install ./app -g

    sudo npm install ./app -g
  7. Install the tfx-cli

    master

    The tfx-cli is a cross-platform Node CLI for interacting with Microsoft Team Foundation Server and Azure DevOps Services.

    Prerequisites:

    • Node.js 4.0.x or later
    • npm (included with Node.js)

    Installation Commands:

    Linux/OSX:

    sudo npm install -g tfx-cli

    Windows:

    npm install -g tfx-cli
    sudo npm install -g tfx-cli
  8. Run tests in tfx-cli

    master

    The project includes server integration tests with an integrated mock server.

    Prerequisite: You must run npm run build before running tests.

    Test Commands:

    • Run all tests: npm test
    • Run specific suites:
      • npm run test:build-commands
      • npm run test:extension-commands
      • npm run test:commandline
      • npm run test:server-integration
    • Run with CI reporter: npm run test:ci

    Debugging Mock Server in Tests: To see detailed request/response info in server integration tests, temporarily modify the createMockServer call in your test file to include verbose: true:

    // In the test file
    mockServer = await createMockServer({ port: 8084, verbose: true });
    npm test
  9. Upload a build task to the server

    master

    Upload an existing build task by pointing to the directory containing the task files using the --task-path flag.

    Important: Build tasks are cached by version on the agent and are considered immutable. If you modify a task's implementation and need to re-upload it, you must increment at least the patch version in the task configuration.

    ~$ tfx build tasks upload --task-path ./CreateOctopusRelease
  10. Create a new build task template

    master

    Use tfx build tasks create to generate a new templated task directory. The CLI will prompt you for a short name, friendly name, description, and author. This creates a local directory containing the necessary task files (icon.png, sample.js, sample.ps1, and task.json) which you can then edit.

    ~$ tfx build tasks create
    Copyright Microsoft Corporation
    
    Enter short name > sample
    Enter friendly name > Sample Task
    Enter description > Sample Task for Docs
    Enter author > Me
    
    created task @ /Users/bryanmac/sample
    id   : 305898e0-3eba-11e5-af7a-1181c3c6c966
    name: sample