Skip to content
Snippets Groups Projects
Commit e4d25f6f authored by Recolic's avatar Recolic 🏡
Browse files

.try:use org url, use new json

parent 1dc24f61
No related branches found
No related tags found
No related merge requests found
...@@ -9,12 +9,20 @@ ...@@ -9,12 +9,20 @@
Should work on all POSIX-compatible systems (`#!/usr/bin/env`) Should work on all POSIX-compatible systems (`#!/usr/bin/env`)
## sample ## use sample
recolic.net test
```
# pat=z42dimrcfgylmvnu7cyzwnzqseom2obwvwaypmtm5id4tigqucmq ./apply.sh --org-url https://dev.azure.com/azvse --proj-name aztest --repo-id a4822210-511f-427f-a36d-26a14c29cc89 --branch bensl/tmpbuild/114514 --build-definition-id 2
```
MS PROD
``` ```
# pat=z42dimrcfgylmvnu7cyzwnzqseom2obwvwaypmtm5id4tigqucmq ./apply.sh --org-name azvse --proj-name aztest --repo-id a4822210-511f-427f-a36d-26a14c29cc89 --branch bensl/tmpbuild/114514 --build-definition-id 2 ./apply.sh --org-url https://msazure.visualstudio.com --proj-name One --repo-name Networking-Datapath-HostSdnStack-SMAgent --branch bensl/tmpbuild/1207.1 --pipeline-name Overlake-Build-PullRequest
./apply.sh --org-name msazure --proj-name One --repo-name Networking-Datapath-HostSdnStack-SMAgent --branch bensl/tmpbuild/1207.1 --pipeline-name Overlake-Build-PullRequest
repo_id: 12e0c399-4e80-42b6-aff2-dc693505d5f7 repo_id: 12e0c399-4e80-42b6-aff2-dc693505d5f7
build_definition_id: 270313 build_definition_id: 270313
``` ```
......
...@@ -3,20 +3,20 @@ ...@@ -3,20 +3,20 @@
show_usage() { show_usage() {
cat <<-EOF cat <<-EOF
Usage: Usage:
$0 --org-name {string} --proj-name {string} [--repo-name {string} | --repo-id {string}] [--branch {string}] [--pipeline-name {string} | --build-definition-id {number}] $0 --org-url {string} --proj-name {string} [--repo-name {string} | --repo-id {string}] [--branch {string}] [--pipeline-name {string} | --build-definition-id {number}]
Examples: Examples:
$0 --org-name azvse --proj-name aztest --repo-name aztest --branch bensl/tmpbuild/1201 --pipeline-name Overlake-Build-PullRequest $0 --org-url azvse --proj-name aztest --repo-name aztest --branch bensl/tmpbuild/1201 --pipeline-name Overlake-Build-PullRequest
$0 --org-name azvse --proj-name aztest --repo-id a4822210-511f-427f-a36d-26a14c29cc89 --branch bensl/tmpbuild/1201 --build-definition-id 2 $0 --org-url azvse --proj-name aztest --repo-id a4822210-511f-427f-a36d-26a14c29cc89 --branch bensl/tmpbuild/1201 --build-definition-id 2
EOF EOF
} }
get_proj_id() { get_proj_id() {
az devops project show \ az devops project show \
--project One \ --project "$proj_name" \
--query "id" \ --query "id" \
--org https://msazure.visualstudio.com/ \ --org "$org_url" \
--output tsv --output tsv
} }
typeset -fx get_proj_id typeset -fx get_proj_id
...@@ -43,8 +43,8 @@ typeset -fx get_build_definition_id ...@@ -43,8 +43,8 @@ typeset -fx get_build_definition_id
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--org-name) --org-url)
org_name=$2 org_url=$2
shift 2 shift 2
;; ;;
--proj-name) --proj-name)
...@@ -82,9 +82,11 @@ while [[ $# -gt 0 ]]; do ...@@ -82,9 +82,11 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
org_url=https://msazure.visualstudio.com/ ############### Harcode! change me!
# user_email="tmp1@recolic.net"
user_email="bensl@microsoft.com"
if [[ ! ${org_name} || ! ${proj_name} || (! ${repo_name} && ! ${repo_id}) || (! ${pipeline_name} && ! ${build_definition_id}) ]]; then if [[ ! ${org_url} || ! ${proj_name} || (! ${repo_name} && ! ${repo_id}) || (! ${pipeline_name} && ! ${build_definition_id}) ]]; then
show_usage show_usage
exit 1 exit 1
fi fi
...@@ -117,7 +119,6 @@ print_policy_list() { ...@@ -117,7 +119,6 @@ print_policy_list() {
--project "${proj_name}" --project "${proj_name}"
} }
user_email="bensl@microsoft.com"
setup_branch_security() { setup_branch_security() {
GIT_REPO_NAMESPACE=2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87 GIT_REPO_NAMESPACE=2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87
az devops security permission update \ az devops security permission update \
...@@ -132,31 +133,57 @@ setup_build_policy() { ...@@ -132,31 +133,57 @@ setup_build_policy() {
curl -X POST "${org_url}/${proj_name}/_apis/policy/configurations?api-version=7.2-preview.1" \ curl -X POST "${org_url}/${proj_name}/_apis/policy/configurations?api-version=7.2-preview.1" \
-H "Authorization: Basic $(echo -n :${pat} | base64)" \ -H "Authorization: Basic $(echo -n :${pat} | base64)" \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
-d ' -d '{
{ "type": {
"isEnabled": true, "id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd"
"isBlocking": true, },
"type": { "revision": 1,
"id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd" "isDeleted": false,
}, "isBlocking": true,
"settings": { "isEnabled": true,
"allowDownvotes": false, "settings": {
"blockLastPusherVote": true, "allowDownvotes": false,
"creatorVoteCounts": false, "blockLastPusherVote": true,
"minimumApproverCount": 2, "creatorVoteCounts": false,
"requireVoteOnEachIteration": true, "requireVoteOnLastIteration": true,
"requireVoteOnLastIteration": true, "resetOnSourcePush": false,
"resetOnSourcePush": false, "resetRejectionsOnSourcePush": false,
"resetRejectionsOnSourcePush": false, "requireVoteOnEachIteration": true,
"scope": [ "minimumApproverCount": 2,
{ "scope": [
"repositoryId": "'${repo_id}'", {
"refName": "refs/heads/'${branch}'", "repositoryId": "'${repo_id}'",
"matchKind": "exact" "refName": "refs/heads/'${branch}'",
} "matchKind": "Exact"
] }
} ]
}' }
}'
# '
# {
# "isEnabled": true,
# "isBlocking": true,
# "type": {
# "id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd"
# },
# "settings": {
# "allowDownvotes": false,
# "blockLastPusherVote": true,
# "creatorVoteCounts": false,
# "minimumApproverCount": 2,
# "requireVoteOnEachIteration": true,
# "requireVoteOnLastIteration": true,
# "resetOnSourcePush": false,
# "resetRejectionsOnSourcePush": false,
# "scope": [
# {
# "repositoryId": "'${repo_id}'",
# "refName": "refs/heads/'${branch}'",
# "matchKind": "exact"
# }
# ]
# }
# }'
} }
setup_build_validation() { setup_build_validation() {
...@@ -175,6 +202,6 @@ setup_build_validation() { ...@@ -175,6 +202,6 @@ setup_build_validation() {
} }
print_policy_list print_policy_list
setup_branch_security #setup_branch_security
setup_build_policy setup_build_policy
setup_build_validation #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