Skip to content
Snippets Groups Projects
Unverified Commit 77cec8da authored by poly000's avatar poly000
Browse files

numerous improvements & pipeline name support

parent b4f5d995
No related branches found
No related tags found
No related merge requests found
# azure-build-policy-apply
## dependencies
- azure-cli (+ devops extension)
- bash
- jq
Should work on all POSIX-compatible systems (`#!/usr/bin/env`)
#!/usr/bin/env bash
if [ $# != 4 ]
if [ $# != 5 ]
then
cat <<-EOF
Usage:
pat=... $0 {org_url} {proj_name} {repo_name} {branch}
pat=... $0 {org_url} {proj_name} {repo_name} {branch} {pipeline_name}
Examples:
pat=... $0 https://dev.azure.com/azvse aztest aztest bensl/tmpbuild/1201
pat=... $0 https://dev.azure.com/azvse aztest aztest bensl/tmpbuild/1201 Overlake-Build-PullRequest
EOF
exit 1
fi
export org_url=$1
export proj_name=$2
export repo_name=$3
export branch=$4
export pipeline_name=$5
if ! [[ ${pat} ]]
then
echo please set pat as your personalAccessToken
exit 2
fi
export org_url=$1
export proj_name=$2
export repo_name=$3
export branch=$4
function get_repo_id {
az repos list --org "${org_url}" \
--proj aztest | \
az repos list \
--org "${org_url}" \
--query '[].{name:name, id:id}' \
--proj "${proj_name}" | \
jq -r ".[] | select(.name == \"${repo_name}\") | .id"
}
# https://unix.stackexchange.com/a/383166
# export function to subshells for bash
typeset -fx get_repo_id
function get_pipeline_definition_id {
az pipelines build definition list \
--org "${org_url}" \
--proj "${proj_name}" \
--repository "${repo_name}" \
--name "${pipeline_name}" \
--query '[0].id'
}
typeset -fx get_pipeline_definition_id
function print_policy_list() {
az repos policy list \
--branch ${branch} \
......@@ -73,8 +86,7 @@ function setup_build_policy() {
}
function setup_build_validation() {
# TODO: get build definition id
build_definition_id=2
build_definition_id=$( get_pipeline_definition_id )
az repos policy build create \
--blocking true \
--branch ${branch} \
......@@ -86,12 +98,11 @@ function setup_build_validation() {
--valid-duration 720 \
--repository-id ${repo_id} \
--org ${org_url} \
--project ${proj_name} \
--project ${proj_name}
}
export repo_id=$( get_repo_id )
print_policy_list
# print_policy_list
setup_build_policy
setup_build_validation
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment