@@ -11,12 +11,12 @@ REM // -------------------------------------------------------------------------
11
11
echo .
12
12
echo Creating Azure DevOps pipelines in the context of:
13
13
echo .
14
- echo DevOps Organization: %DEVOPS_ORG%
15
- echo DevOps Project: %DEVOPS_PROJECT_NAME%
16
- echo Repository Name/URL: %DEVOPS_REPO_NAME_OR_URL%
17
- echo Repository Type: %DEVOPS_REPO_TYPE%
18
- echo Repository Branch: %DEVOPS_REPO_BRANCH%
19
- echo Azure Pipeline Suffix: %DEVOPS_PIPELINE_NAME_SUFFIX%
14
+ echo DevOps Organization: %DEVOPS_ORG%
15
+ echo DevOps Project: %DEVOPS_PROJECT_NAME%
16
+ echo Repository Name/URL: %DEVOPS_REPO_NAME_OR_URL%
17
+ echo Repository Type: %DEVOPS_REPO_TYPE%
18
+ echo Repository Branch ^ & Environment: %DEVOPS_REPO_BRANCH%
19
+ echo Azure Pipeline Suffix: %DEVOPS_PIPELINE_NAME_SUFFIX%
20
20
echo .
21
21
choice /C YN /M " Do you want to proceed?"
22
22
if errorlevel 2 exit /b 0
@@ -26,7 +26,7 @@ for %%N in (management-groups roles platform-logging policy platform-connectivit
26
26
27
27
REM Check for pipeline existence
28
28
set FOUND =
29
- for /f usebackq %%F in (`call az pipelines list -o tsv --query=" [?name=='%%N - %DEVOPS_PIPELINE_NAME_SUFFIX% '].name | [0]" `) do set FOUND = true
29
+ for /f usebackq %%F in (`call az pipelines list -o tsv --query=" [?name=='%%N %DEVOPS_PIPELINE_NAME_SUFFIX% '].name | [0]" `) do set FOUND = true
30
30
31
31
REM Only create Azure DevOps pipeline if it does *not* already exist
32
32
if not defined FOUND (
@@ -36,3 +36,29 @@ for %%N in (management-groups roles platform-logging policy platform-connectivit
36
36
echo Pipeline [%%N %DEVOPS_PIPELINE_NAME_SUFFIX% ] already exists. Skipping creation.
37
37
)
38
38
)
39
+
40
+ REM Get environments in the project
41
+ echo .
42
+ echo Retrieving list of environments for project [%DEVOPS_PROJECT_NAME% ]..
43
+ call az devops invoke --organization " %DEVOPS_ORG% " --route-parameters project=" %DEVOPS_PROJECT_NAME% " --http-method GET --api-version 6.0 --area distributedtask --resource environments -o json > %DEVOPS_OUTPUT_DIR% \environment.json
44
+
45
+ REM Check if environment matching repository branch name exists
46
+ set ENVIRONMENT =
47
+ echo Checking project for existing environment [%DEVOPS_REPO_BRANCH% ]...
48
+ for /f " usebackq delims=" %%E in (`jq " .value[] | select(.name == \" %DEVOPS_REPO_BRANCH% \" ) | .name" %DEVOPS_OUTPUT_DIR% \environment.json`) do set ENVIRONMENT = %%~E
49
+
50
+ REM Create environment if it doesn't already exist
51
+ if not defined ENVIRONMENT (
52
+ echo Creating environment [%DEVOPS_REPO_BRANCH% ]...
53
+ echo { " name" : " %DEVOPS_REPO_BRANCH% " } > %DEVOPS_OUTPUT_DIR% \environment-body.json
54
+ call az devops invoke --organization " %DEVOPS_ORG% " --route-parameters project=" %DEVOPS_PROJECT_NAME% " --http-method POST --api-version 6.0 --area distributedtask --resource environments --in-file %DEVOPS_OUTPUT_DIR% \environment-body.json > nul
55
+ ) else (
56
+ echo Environment [%DEVOPS_REPO_BRANCH% ] already exists. Skipping creation.
57
+ )
58
+
59
+ echo .
60
+ echo Now that an environment exists for the repository branch [%DEVOPS_REPO_BRANCH% ],
61
+ echo learn more about configuring approvals and checks for deployments associated with this
62
+ echo environment by reviewing the following documentation:
63
+ echo * https://docs.microsoft.com/azure/devops/pipelines/process/approvals
64
+ echo .
0 commit comments