Originally From colinsalmcorner
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 $YmlPathNote: 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 $trueNote: The --allow-override is the checkbox on the UI that allows users to override the variable value at queue time.
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 $YmlPathNow 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: ")