Create and manage Azure Pipelines from the command line

George Verghese

We recently introduced a unified YAML experience in Azure Pipelines where you can configure pipelines to do CI, CD or CI and CD together. Over the past few months we have been building capability to manage YAML backed pipelines from the command line to cater to developers who prefer working from the command line interface or require commands to automate set up and management. We are excited to announce the availability of az pipelines command in the Azure DevOps extension for developers who want to create and manage YAML backed Azure Pipelines from the CLI. The az pipelines command group allows you to create, delete, list, run, show and update a pipeline, enabling you to manage pipelines effectively from the command line.

Create an Azure Pipeline from the command line

Interacting from the command line can get challenging by having to remember various parameters and keying it in properly. To make things simple, we have crafted the az pipelines create command by letting developers go from a Git repo to a pipeline through an easy to use interactive flow, eliminating any need to remember a bunch of parameters.
1. To start, you need the Azure CLI with the Azure DevOps extension installed. Have a look at the Azure DevOps CLI – Get Started documentation for details.
2. Clone your Git repository and navigate to the repo directory.
3. Run az pipelines create:
az pipelines create --name "Contoso.CI"
4. Follow the steps to set up the pipeline.

Check out the documentation for more details.

You can also automate the entire pipeline creation process by providing a reference to a YAML file inside your repository. Picking up from the example above, imagine you had the completed YAML available in the repository; you can create the pipeline by simply running the command:
az pipelines create --name "Contoso.CI" --yml-path /azure-pipelines.yml

YAML run of pipeline

Manage Azure Pipeline runs

Once the pipeline is created, a pipeline run is triggered. You can use the az pipelines runs command group to manage pipelines runs. Use az pipelines runs list command to view all pipelines runs and az pipelines runs show command to view details pertaining to a particular run.

The az pipelines runs command group also contains the artifact and tag command sub groups which are used to manage artifacts pertaining to a run or tag a run, respectively.

Refer the az pipelines runs command documentation for details pertaining to usage and syntax.

For DevOps professionals who prefer to work from the command line, the az pipelines commands let you manage Azure Pipelines right from the terminal, without having to navigate to the portal. If you have any changes you’d like or suggestions for features then we’d love your feedback in our Azure DevOps extension GitHub Repo.

7 comments

Discussion is closed. Login to edit/delete existing comments.

  • Prashanth Srivathsan J 0

    Hi,
    I tried the same commands in creating a sample Build definition. Got the below error when tried using the az pipelines create command – 
    az : ERROR: az pipelines: ‘create’ is not in the ‘az pipelines’ command group. See ‘az pipelines –help’.
    The version of Azure CLI and it’s associated modules’ – 
    azure-cli 2.0.68
    command-modules-nspkg 2.0.2 *core 2.0.68nspkg 3.0.4telemetry 1.0.3
    Extensions:azure-devops 0.5.0
    Python location ‘C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe’Extensions directory ‘C:\Users\X123050\.azure\cliextensions’
    Python (Windows) 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 02:47:15) [MSC v.1900 32 bit (Intel)]
    Need your insight in pointing out the reason behind the error.
    Thanks in Advance
    Srivathsan J

    • George VergheseMicrosoft employee 0

      Hey Prashanth – you would need to update your azure devops extension to 0.6.0 or above. You can run az extension update –name azure-devops to pull the latest version. Let me know if this doesn’t work.

      You can also reach out to us at our GitHub page – https://github.com/Azure/azure-devops-cli-extension to raise any issues, feature requests or provide feedback.

      • Prashanth Srivathsan J 0

        Hi George,
        After the update of azure devops, i am able to create the build through commmands. i am trying to automate the process of build creations. Is there a way to have the yaml template in a common tfs git repo and create build definition for another git repo in the same project collection. 
        Thanks,
        Srivathsan J

        • George VergheseMicrosoft employee 0

          Hey Prashanth – when creating Azure Pipelines using the create command with an existing YAML file, the expectation is that the YAML file is within the repo for which you are creating the pipeline. This is the reason why the YAML path expects relative path in the create command.

  • Andrei Fokau 0

    Hi, George! Is there any way to create pipline release definition from CLI?

    • Andreas Larsson 0

      I have the exact same question. The CLI documentation states that you should pass the definition(id or name) that you want the release to use. But what if you don’t want to use any of the existing definitions? What if you want to create a new definition for the release you are creating. I have read through the CLI documentation but I can’t find anything useful.

      The REST API has an endpoint for this: https://docs.microsoft.com/en-us/rest/api/azure/devops/release/definitions?view=azure-devops-rest-5.1
      The REST API documentation also lists creating definitions as a common task which makes me wonder why CLI documentation does not mention creation of definitions at all?

      • George VergheseMicrosoft employee 0

        Apologies for the delayed response. We do not have a command to create a release definition yet. Feel free to raise a feature request on our Github Repo Azure/azure-devops-cli-extension.

        However, we do have an

        az devops invoke

        command that can be used to call into the create release definition API from script. You can refer the command documentation here. This can be useful when you want to script out your entire automation use case.

Feedback usabilla icon