Skip to content

Commit

Permalink
Adding scaffolding script and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
geverghe committed May 24, 2019
1 parent 535b137 commit fdbb055
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 0 deletions.
104 changes: 104 additions & 0 deletions examples/Scaffolding_Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
**Scaffolding.ps1** is a powershell script which helps users of an organization to have a standard getting started experience.

## Sample command to invoke the script –

.\scaffolding.ps1 -filePath .\org_details.txt

## Input parameters expected

You can either interactively provide inputs or pass a file instead. The contents of file would look something like this:

org=https://dev.azure.com/contoso

projectName=cliDemoScaffolding

repoName=cli_repo

repoToImport = https://github.com/ishitam8/snake.git

teamName=Protocol CLI team

optionalReviewers=user1@contoso.com,user2@contoso.com

requiredReviewers=user3@contoso.com,user4@contoso.com

teamMembers=user1@contoso.com,user2@contoso.com,user3@contoso.com

teamAdminMembers=admin1@contoso.com,admin2@contoso.com

childIterationNamesList=Sprint 1,Sprint 2,Sprint 3

iterationsPermissionsBit=7

## What does this script do

1. Your organization URL

[org=https://dev.azure.com/contoso]

2. Creates a new project under this organization

[projectName=cliDemoScaffolding]

3. Creates a new Repository

[repoName=cli_repo]

4. Repository URL to be imported in the newly created repo

[repoToImport = https://github.com/ishitam8/snake.git]

Accepts only public repo URL.

5. List of required reviewers for configuring branch policies

[requiredReviewers=user1@contoso.com,user2@contoso.com]

Currently, these branch policies are applied on master.

6. List of required reviewers for configuring branch policies

[optionalReviewers=user3@contoso.com,user4@contoso.com]

Currently, these branch policies are applied on master.

7. Creates a team

[teamName=Protocol CLI team]

8. Adds the list of team members to the new team

[teamMembers=user1@contoso.com,user2@contoso.com,user3@contoso.com]

9. Creates a corresponding admins group which would be used to manage this team.

Add this admins group as `Team administrator` of this team.

10. Adds the list of admin members to the team admin group

[teamAdminMembers=admin1@contoso.com,admin2@contoso.com]

11. Boards settings for this team

Setting up area

- Creates a new area for this team and sets it to default area for this team.

Iterations related settings

- Creates a root iteration by the same name as team [i.e teamName].
- Creates child iterations which will be added this root iteration
[childIterationNamesList=Sprint1,Sprint2,Sprint3].
- Configure/add these root and child iterations to the newly created team.
- Give iterations related permissions to the admins group
[iterationsPermissionsBit=7]
The permission bit 7 denotes the addition of required permission bits to be allowed to this admins group.
Which shall be as follows
View permissions for this node = 1
Edit this node = 2
Create child nodes = 4

General settings

- Configure backlog navigation settings [Currently assumed as epics: true, features: true, stories: true]
- Configure working days [Currently assumed as Monday to Friday]
131 changes: 131 additions & 0 deletions examples/scaffolding.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@

param(
[String]$filePath
)
. (Join-Path $PSScriptRoot .\Boards\boardsettings.ps1)
. (Join-Path $PSScriptRoot .\Repos\setPolicies.ps1)
. (Join-Path $PSScriptRoot .\configureTeam.ps1)


#get input params

if (!$filePath) {
Write-Host("`nFile input not provided so switching the script to interactive mode to ask default parameters.")
$org = "https://dev.azure.com/CliDemo" # Read-host("`nOrganization URL ")
$projectName = Read-host("Project Name ")
$repoName = Read-host("Repo Name ")
$repoToImport = Read-host("Repo Import URL ")

$requiredReviewersInput = Read-host("Required reviewers(Comma separated EMail IDs) ")
$requiredReviewers = if ($requiredReviewersInput) { $requiredReviewersInput.split(",") }

$optionalReviewersInput = Read-host("Optional reviewers(Comma separated EMail IDs) ")
$optionalReviewers = if ($optionalReviewersInput) { $optionalReviewersInput.split(",") }

$teamName = Read-host("Team Name ")

$teamMembersInput = Read-host("Team Members(Comma separated EMail IDs) ")
$teamMembers = if ($teamMembersInput) { $teamMembersInput.split(",") }

$teamAdminMembersInput = Read-host("Team Admin Members(Comma separated EMail IDs) ")
$teamAdminMembers = if ($teamAdminMembersInput) { $teamAdminMembersInput.split(",") }


$childIterationNamesInput = Read-host("Child iterations list(Comma separated) ")
$childIterationNamesList = if ($childIterationNamesInput) { $childIterationNamesInput.split(",") }

Write-Host("`nThanks for providing all the required details. Now just sit back and relax, script is in action now . . . ")
}
else {
$values = Get-Content $filePath | Out-String | ConvertFrom-StringData
$org = $values.org
$projectName = $values.projectName
$repoName = $values.repoName
$repoToImport = $values.repoToImport
$teamName = $values.teamName
$requiredReviewers = $values.requiredReviewers.split(",")
$optionalReviewers = $values.optionalReviewers.split(",")
$teamMembers = $values.teamMembers.split(",")
$teamAdminMembers = $values.teamAdminMembers.split(",")
$childIterationNamesList = $values.childIterationNamesList.split(",")
$iterationsPermissionsBit = $values.iterationsPermissionsBit

Write-Host("`nAll the required parameters are read from file at $($filePath) Now just sit back and relax, script is in action now . . . ")
}

$invokeRequestsPath = . Join-Path $PSScriptRoot InvokeRequests\
If (!(test-path $invokeRequestsPath)) {
New-Item -ItemType Directory -Force -Path $invokeRequestsPath
}

# scaffolding
Write-Host "`nCreating project with name $($projectName) . . . "
$project = az devops project create --org $org --name $projectName --process Agile -o json | ConvertFrom-Json
Write-Host "Created project with name $($project.name) and Id $($project.id)"


if ($repoName) {
Write-Host "`nCreating repository with name $($repoName) . . . "
$repo = az repos create --org $org -p $projectName --name $repoName -o json | ConvertFrom-Json
Write-Host "Created repository with name $($repo.name) and Id $($repo.id)"

if ($repoToImport) {
Write-Host "`nImporting repository from url $($repoToImport)"
$importRepo = az repos import create --org $org -p $project.id -r $repo.id --git-url $repoToImport -o json | ConvertFrom-Json
Write-Host "Repo imported with Status $($importRepo.status)"
if ($requiredReviewers -or $optionalReviewers) {
$policiesSet = set_policies -org $org -projectName $project.id -repoId $repo.id -branch 'master' -requiredApprovers $requiredReviewers -optionalApprovers $optionalReviewers
Write-Host "`nBranch policies set for master"
}
}
}
else {
Write-Host "`nSkipping repo creation as repo name is empty"
}

# team set up
$apiVersion = '5.0'
if ($teamName) {
Write-Host "`nCreating team with name $($teamName) . . . "
$createTeam = az devops team create --name $teamName --org $org -p $project.id -o json | ConvertFrom-Json
Write-Host "Created team with name $($createTeam.name) and Id $($createTeam.id)"
if ($teamMembers) {
$listGroups = az devops security group list --org $org -p $project.id -o json | ConvertFrom-Json
foreach ($grp in $listGroups.graphGroups) {
if ($grp.displayName -eq $teamName) {
# Add team members
addTeamMembers -org $org -teamMembersList $teamMembers -teamDescriptor $grp.descriptor
# create a team admin group and add it to this team
$teamAdminGroupName = $teamName + ' Admins'
$createTeamAdminsGroup = az devops security group create --org $org -p $project.id --name $teamAdminGroupName --groups $grp.descriptor -o json | ConvertFrom-Json
Write-Host "`nCreated new admin group with name $($teamAdminGroupName) and added to the newly created team $($createTeam.name)."

if ($teamAdminMembers) {
addTeamMembers -org $org -teamMembersList $teamAdminMembers -teamDescriptor $createTeamAdminsGroup.descriptor
}
# add this newly created Admin group as Team Administrators
addTeamAdmins -org $org -projectID $project.id -teamID $($createTeam.id) -adminGrpDescriptor $createTeamAdminsGroup.descriptor

#create Area for this team
createTeamArea -org $org -projectID $project.id -areaName $teamName

# area path
$areaPath = $projectName + '\' + $teamName
configureDefaultArea -org $org -projectID $project.id -teamID $($createTeam.id) -defaultAreaPath $areaPath

# Configure project level iterations with this group/team and grant permissions for admins group
$projectIterationNameForThisTeam = $teamName + ' iteration'
$rootIterationId = projectLevelIterationsSettings -org $org -projectID $project.id -rootIterationName $projectIterationNameForThisTeam -subject $createTeamAdminsGroup.descriptor -allow $iterationsPermissionsBit -childIterationNamesList $childIterationNamesList

# Boards General settings
setUpGeneralBoardSettings -org $org -projectID $project.id -teamID $($createTeam.id) -backlogIterationId $rootIterationId -epics $true -stories $true -features $true

# Add child iterations of backlog iteration to the given team
setUpTeamIterations -org $org -projectID $project.id -teamID $($createTeam.id) -backlogIterationName $projectIterationNameForThisTeam
}
}
}
}

# clean up temp files for invoke requests
Remove-Item -path .\InvokeRequests\ -recurse

0 comments on commit fdbb055

Please sign in to comment.