Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Last active March 25, 2024 20:04
Show Gist options
  • Select an option

  • Save sheldonhull/3ff743b66b7fb031eb82530fb122c30b to your computer and use it in GitHub Desktop.

Select an option

Save sheldonhull/3ff743b66b7fb031eb82530fb122c30b to your computer and use it in GitHub Desktop.
[Azure Pipelines Link from CLI] configure a new pipline without having to do through browser #azurepipelines

Originally From colinsalmcorner

Example 10: Creating a YML Pipeline

To create a YML pipeline, you'll need a name as well as the repository, branch and path to the YML file within the repo (the path relative to the root path of the repo):

az pipelines create -p $ProjectName --org $orgUrl --name $PipelineName --description $PipelineDescription --repository $RepoName --repository-type tfsgit --branch master --skip-first-run --yml-path $YmlPath

Note: The --skip-first-run tells Azure DevOps not to immediately run the pipeline. If you do not specify this, the pipeline is automatically queued. If you need UI variables for the pipeline, you can add these using az pipelines variables create like this:

az pipelines variable create -p $ProjectName --org $orgUrl --pipeline-name $PipelineName --name myVar --value "some value" --allow-override $true

Note: The --allow-override is the checkbox on the UI that allows users to override the variable value at queue time.

Script Example

ProjectName=${AZURE_DEVOPS_PROJECT}
orgUrl=${AZURE_DEVOPS_ORGANIZATION}
PipelineName=
PipelineDescription=
RepoName=
YmlPath=
az pipelines create -p $ProjectName --org $orgUrl --name $PipelineName --description $PipelineDescription --repository $RepoName --repository-type tfsgit --branch master --skip-first-run --yml-path $YmlPath

Now configure the build policy (could route the json from first command into variable and use it here too. (just didn't have time to do this yet 😁)

az repos policy build create --blocking 'true' \
                             --branch $(gum input --prompt "Default Branch: ") \
                             --build-definition-id  $(gum input --prompt "Build Definition ID: ") \
                             --display-name $(gum input --prompt "Display Name: (example: '🧪 go-standard-tests': ") \
                             --enabled 'true' \
                             --manual-queue-only 'false' \
                             --queue-on-source-update-only 'true' \
                             --detect 'true' \
                             --valid-duration 1440 \
                             --path-filter "$(gum input --prompt "Path Filter: (example: '*.go;go.mod;go.sum;'): ")" \
                             --repository-id $(gum input --prompt "Repository ID: ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment