Create your first pipeline from the CLI

Azure Pipelines

This is a step-by-step guide to using Azure Pipelines from the Azure CLI (command-line interface) to build a GitHub repository. You can use Azure Pipelines to build an app written in any language. For this quickstart, you'll use Java.

Prerequisites

  • A GitHub account, where you can create a repository. If you don't have one, you can create one for free.

  • An Azure DevOps organization. If you don't have one, you can create one for free. (An Azure DevOps organization is different from your GitHub organization. Give them the same name if you want alignment between them.)

    If your team already has one, then make sure you're an administrator of the Azure DevOps project that you want to use.

  • Azure CLI version 2.0.49 or newer.

    az --version
    
  • The Azure DevOps extension.

    • To install from the command prompt:
    az extension add --name azure-devops
    
    • To confirm installation from the command prompt:
    az extension show --name azure-devops
    
  • Make sure your Azure DevOps defaults include the organization and project from the command prompt:

    az devops configure --defaults organization=https://dev.azure.com/your-organization project=your-project
    

Get your first run

  1. From a command prompt, sign in to the Azure CLI.

    az login
    
  2. Fork the following repository into your GitHub account:

    https://github.com/MicrosoftDocs/pipelines-java
    

    After you've forked it, clone it to your dev machine. Learn how: Fork a repo.

  3. Navigate to the cloned directory.

  4. Create a new pipeline:

    az pipelines create --name "First-Java.CI"
    

    The repository and branch details are picked up from the git configuration available in the cloned directory.

  5. Enter your GitHub user name and password to authenticate Azure Pipelines.

    Enter your GitHub username (Leave blank for using already generated PAT): Contoso
    
    Enter your GitHub password:
    
  6. Provide a name for the service connection created to enable Azure Pipelines to communicate with the GitHub Repository.

    Enter a service connection name to create? ContosoPipelineServiceConnection
    
  7. Select the Maven pipeline template from the list of recommended templates.

    Which template do you want to use for this pipeline?
    [1] Maven
    [2] Maven package Java project Web App to Linux on Azure
    [3] Android
    [4] Ant
    [5] ASP.NET
    [6] ASP.NET Core
    [7] ASP .NET Core (.NET Framework)
    [8] Starter pipeline
    [9] C/C++ with GCC
    [10] Go
    [11] Gradle
    [12] HTML
    [13] Jekyll site
    [14] .NET Desktop
    [15] Node.js
    [16] Node.js with Angular
    [17] Node.js with Grunt
    [18] Node.js with gulp
    [19] Node.js with React
    [20] Node.js with Vue
    [21] Node.js with webpack
    [22] PHP
    [23] Python Django
    [24] Python package
    [25] Ruby
    [26] Universal Windows Platform
    [27] Xamarin.Android
    [28] Xamarin.iOS
    [29] Xcode
    Please enter a choice [Default choice(1)]:
    
  8. The pipeline YAML is generated. You can open the YAML in your default editor to view and make changes.

    Do you want to view/edit the template yaml before proceeding?
    [1] Continue with the generated yaml
    [2] View or edit the yaml
    Please enter a choice [Default choice(1)]:2
    
  9. Provide where you want to commit the YAML file that is generated.

    How do you want to commit the files to the repository?
    [1] Commit directly to the master branch.
    [2] Create a new branch for this commit and start a pull request.
    Please enter a choice [Default choice(1)]:
    
  10. A new run is started. Wait for the run to finish.

Manage your pipelines

You can manage the pipelines in your organization using these az pipelines commands:

These commands require either the name or ID of the pipeline you want to manage. You can get the ID of a pipeline using the az pipelines list command.

Run a pipeline

You can queue (run) an existing pipeline with the az pipelines run command. To get started, see Get started with Azure DevOps CLI.

az pipelines run [--branch]
                 [--commit-id]
                 [--folder-path]
                 [--id]
                 [--name]
                 [--open]
                 [--org]
                 [--project]
                 [--variables]

Parameters

  • branch: Name of the branch on which the pipeline run is to be queued, for example, refs/heads/master.
  • commit-id: Commit-id on which the pipeline run is to be queued.
  • folder-path: Folder path of pipeline. Default is root level folder.
  • id: Required if name is not supplied. ID of the pipeline to queue.
  • name: Required if ID is not supplied, but ignored if ID is supplied. Name of the pipeline to queue.
  • open: Open the pipeline results page in your web browser.
  • org: Azure DevOps organization URL. You can configure the default organization using az devops configure -d organization=ORG_URL. Required if not configured as default or picked up using git config. Example: --org https://dev.azure.com/MyOrganizationName/.
  • project: Name or ID of the project. You can configure the default project using az devops configure -d project=NAME_OR_ID. Required if not configured as default or picked up using git config.
  • variables: Space separated "name=value" pairs for the variables you would like to set.

Example

The following command runs the pipeline named myGithubname.pipelines-java in the branch pipeline and shows the result in table format.

az pipelines run --name myGithubname.pipelines-java --branch pipeline --output table

Run ID    Number      Status      Result    Pipeline ID    Pipeline Name                Source Branch    Queued Time               Reason
--------  ----------  ----------  --------  -------------  ---------------------------  ---------------  --------------------------  --------
123       20200123.2  notStarted            12             myGithubname.pipelines-java  pipeline           2020-01-23 11:55:56.633450  manual

Update a pipeline

You can update an existing pipeline with the az pipelines update command. To get started, see Get started with Azure DevOps CLI.

az pipelines update [--branch]
                    [--description]
                    [--id]
                    [--name]
                    [--new-folder-path]
                    [--new-name]
                    [--org]
                    [--project]
                    [--queue-id]
                    [--yaml-path]

Parameters

  • branch: Name of the branch on which the pipeline run is to be configured, for example, refs/heads/master.
  • description: New description for the pipeline.
  • id: Required if name is not supplied. ID of the pipeline to update.
  • name: Required if ID is not supplied. Name of the pipeline to update.
  • new-folder-path: New full path of the folder to which the pipeline is moved, for example, user1/production_pipelines.
  • new-name: New updated name of the pipeline.
  • org: Azure DevOps organization URL. You can configure the default organization using az devops configure -d organization=ORG_URL. Required if not configured as default or picked up using git config. Example: --org https://dev.azure.com/MyOrganizationName/.
  • project: Name or ID of the project. You can configure the default project using az devops configure -d project=NAME_OR_ID. Required if not configured as default or picked up using git config.
  • queue-id: Queue ID of the agent pool where the pipeline needs to run.
  • yaml-path: Path of the pipeline's yaml file in the repo.

Example

The following command updates the pipeline with the ID of 12 with a new name and description and shows the result in table format.

az pipelines update --id 12 --description "rename pipeline" --new-name updatedname.pipelines-java --output table

ID    Name                        Status    Default Queue
----  --------------------------  --------  ------------------
12    updatedname.pipelines-java  enabled   Hosted Ubuntu 1604

Show pipeline

You can view the details of an existing pipeline with the az pipelines show command. To get started, see Get started with Azure DevOps CLI.

az pipelines show [--folder-path]
                  [--id]
                  [--name]
                  [--open]
                  [--org]
                  [--project]

Parameters

  • folder-path: Folder path of pipeline. Default is root level folder.
  • id: Required if name is not supplied. ID of the pipeline to show details.
  • name: Required if name is not supplied, but ignored if ID is supplied. Name of the pipeline to show details.
  • open: Open the pipeline summary page in your web browser.
  • org: Azure DevOps organization URL. You can configure the default organization using az devops configure -d organization=ORG_URL. Required if not configured as default or picked up using git config. Example: --org https://dev.azure.com/MyOrganizationName/.
  • project: Name or ID of the project. You can configure the default project using az devops configure -d project=NAME_OR_ID. Required if not configured as default or picked up using git config.

Example

The following command shows the details of the pipeline with the ID of 12 and returns the result in table format.

az pipelines show --id 12 --output table

ID    Name                        Status    Default Queue
----  --------------------------  --------  ------------------
12    updatedname.pipelines-java  enabled   Hosted Ubuntu 1604

Add a status badge to your repository

Many developers like to show that they're keeping their code quality high by displaying a status badge in their repo.

Status badge shows Azure pipeline succeeded

To copy the status badge to your clipboard:

  1. In Azure Pipelines, go to the Pipelines page to view the list of pipelines. Select the pipeline you created in the previous section.

  2. In the context menu for the pipeline, select Status badge.

  3. Copy the sample Markdown from the status badge panel.

Now with the badge Markdown in your clipboard, take the following steps in GitHub:

  1. Go to the list of files and select Readme.md. Select the pencil icon to edit.

  2. Paste the status badge Markdown at the beginning of the file.

  3. Commit the change to the master branch.

  4. Notice that the status badge appears in the description of your repository.

To configure anonymous access to badges:

  1. Navigate to Project Settings

  2. Open the Settings tab under Pipelines

  3. Toggle the Disable anonymous access to badges slider under General

Note

Even in a private project, anonymous badge access is enabled by default. With anonymous badge access enabled, users outside your organization might be able to query information such as project names, branch names, job names, and build status through the badge status API.

Because you just changed the Readme.md file in this repository, Azure Pipelines automatically builds your code, according to the configuration in the azure-pipelines.yml file at the root of your repository. Back in Azure Pipelines, observe that a new run appears. Each time you make an edit, Azure Pipelines starts a new run.

Next steps

You've just learned how to create your first Azure Pipeline. Learn more about configuring pipelines in the language of your choice:

Or, you can proceed to customize the pipeline you just created.

To run your pipeline in a container, see Container jobs.

For details about building GitHub repositories, see Build GitHub repositories.

To learn what else you can do in YAML pipelines, see YAML schema reference.

Clean up

If you created any test pipelines, they are easy to delete when you are done with them.

To delete a pipeline, navigate to the summary page for that pipeline, and choose Delete from the ... menu at the top-right of the page. Type the name of the pipeline to confirm, and choose Delete.

Delete pipeline