Search code examples
azure-devopsazure-pipelinesazure-devops-extensions

Is it possible to clone an Azure Pipeline? (meta-yaml for devops?)


I have a pipeline that could be reused in different subscriptions, projects, and clients. It contains a various set of best practices for Infrastructure plumbing code.

Does AzureDevops have a way to export the pipeline, related dependencies (assets), and ideally allow for parameterized substitution on import? (e.g. project name)


Solution

  • Only the classic(UI mode) pipeline in Azure DevOps can be exported.

    As for yaml pipeline, its definition is already in a code file(yml file) which means it can always be reused.

    Once you created this yaml file, each time you want to reuse it to create a new pipeline, click New pipeline - Use the classic editor - Select a source - Choose YAML in Select a template - select yaml file path.

    However, one thing to notice is that, once you edited the yaml file in your new created pipeline, it will affect other pipelines using the same yaml file as their definition, unless you download and upload the file to other banrches and created new pipelines there.

    To resolve this issue, the Templates which are also yaml files that can be used repeatedly and it accepts parameters which can be "parameterized substitution on import", different yaml pipelines using the same templates won't affect each other.

    For example, a template contains a parameter:

    # File: simple-param.yml
    parameters:
    - name: yesNo # name of the parameter; required
      type: boolean # data type of the parameter; required
      default: false
    
    steps:
    - script: echo ${{ parameters.yesNo }}
    

    A yaml pipeline uses this template:

    # File: azure-pipelines.yml
    trigger:
    - master
    
    extends:
      template: simple-param.yml
      parameters:
          yesNo: false # set to a non-boolean value to have the build fail