Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 5d7eec3

Browse files
authored
Update create-pipelines.bat onboarding script to auto-provision environment (Azure#178)
1 parent 488fc6e commit 5d7eec3

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

scripts/onboarding/create-pipelines.bat

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ REM // -------------------------------------------------------------------------
1111
echo.
1212
echo Creating Azure DevOps pipelines in the context of:
1313
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%
2020
echo.
2121
choice /C YN /M "Do you want to proceed?"
2222
if errorlevel 2 exit /b 0
@@ -26,7 +26,7 @@ for %%N in (management-groups roles platform-logging policy platform-connectivit
2626

2727
REM Check for pipeline existence
2828
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
3030

3131
REM Only create Azure DevOps pipeline if it does *not* already exist
3232
if not defined FOUND (
@@ -36,3 +36,29 @@ for %%N in (management-groups roles platform-logging policy platform-connectivit
3636
echo Pipeline [%%N%DEVOPS_PIPELINE_NAME_SUFFIX%] already exists. Skipping creation.
3737
)
3838
)
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

Comments
 (0)