Git Product home page Git Product logo

azure-devops-run-pipeline's Introduction

Azure DevOps Run Pipeline Template

This is a generic template that can be used to invoke the execution of a pipeline from another pipeline. You will need to provide your own Personal Access Token in order to authenticate to the API. It is best to store this as a secret variable in a Library Variable Group.

Usage

This template is designed to operate at the root level of an Azure Pipeline. It has its own stages declaration. To use this template, add the following two segments to your azure-pipelines.yml:

First add a resource definition for the repository

resources:
  repositories:
  - repository: run-pipeline
    type: github
    name: lifesoccult/azure-devops-run-pipeline

Next add the template reference at the point you want to call another pipeline:

- template: run-pipeline.yml@run-pipeline
  parameters:
    organization: <str> # Name of your ADO Organization
    project: <str> # Name of your ADO Project
    pipeline_id: <int> # Get ID from the web URI
    pipeline_branch: <str> # Optional, defaults to 'main'
    pipeline_variables: <JSON blob> # Optional, defaults to '{}'. See working examples below for good structure
    stages_to_skip: <str[]> # Optional, defaults to '[]' 
    ado_token: <PAT> # It is recommended to use a secret variable for safe keeping

Example

Here is an example of the template declaration fully populated

- template: run-pipeline.yml@run-pipeline
  parameters:
    organization: contoso
    project: ADO
    pipeline_id: 42
    pipeline_branch: develop
    pipeline_variables: "{'environment': {'value': 'dev'}, 'var1': {'value': 'foo'}, 'var2': {'value': 'bar'}}"
    stages_to_skip: "['deploy']"
    ado_token: $(ado_token)

A Note on Pipeline Variables

There is a specific format for this argument based on the API documentation. The isSecret key/value pair is optional. It is recommended to condense the JSON blob to a single line.

In my testing, it seems that you cannot override variables that are defined in your pipeline YAML. For best results, I opted to leave out all variable declarations in the target pipeline I wish to trigger, realizing this is not the most optional solution as those variable names are now obfuscated from anyone reading that pipeline code.

These examples are completely dependent on the pipeline you intend to invoke. If you do not need to pass in variables, you can ignore this parameter altogether.

Condensed, sans isSecret key example:

pipeline_variables: "{'environment': {'value': 'dev'}, 'var1': {'value': 'foo'}, 'var2': {'value': 'bar'}}"

Non-condensed example:

pipeline_variables: "{
    'environment': {
        'isSecret': false,
        'value': 'dev'
        },
    'var1': {
        'isSecret': false,
        'value': 'foo'
        },
    'var2': {
        'isSecret': false,
        'value': 'bar'
        }
    }
}"

azure-devops-run-pipeline's People

Contributors

lifesoccult avatar

Stargazers

 avatar

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.