11

使用 Azure CLI 快速新增使用者到 Azure DevOps 組織並授予專案權限

 3 years ago
source link: https://blog.miniasp.com/post/2021/07/13/Azure-DevOps-CLI-Add-User-and-Project-Security-Group
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

最近公司正在急速的成長,經常需要新增 Azure DevOps Services 使用者帳號並設定專案權限,我今天特別將這些步驟全部寫成指令碼,之後直接複製貼上就可以單鍵完成設定。

安裝 Azure CLI 並安裝 Azure DevOps Services 擴充命令

  1. 安裝 Azure CLI 工具

    choco install azure-cli -y
    
  2. 登入 Azure

    az login
    
  3. 安裝 Azure DevOps Services 擴充命令

    az extension add --name azure-devops
    
  4. 設定組織預設值

    az devops configure --defaults organization=https://dev.azure.com/YourOrgName
    

新增使用者到 Azure DevOps Services 組織

新增到使用者,最主要有兩個設定:

常見的 AccountLicenseType 只有四種:

我們假設 $UserPrincipalName 是 PowerShell 變數,並指向類似 [email protected] 的電子郵件地址。

  • Stakeholder

    az devops user add --email-id $UserPrincipalName --license-type "stakeholder"
    
  • Basic

    az devops user add --email-id $UserPrincipalName --license-type "express"
    
  • Basic + Test Plans

    az devops user add --email-id $UserPrincipalName --license-type "advanced"
    
  • Visual Studio subscriber

    az devops user add --email-id $UserPrincipalName --license-type "none"
    

新增使用者到特定專案下的特定群組

  1. 首先,我們要先確定你要把使用者加入到哪個專案

    $AzDO_Project = "TDCC_Futures"
    
  2. 取得 Azure DevOps Services 特定專案的群組清單

    # 取得 Azure DevOps Services 特定專案的群組清單
    $AzDO_Groups = $(az devops security group list -p $AzDO_Project -o json | ConvertFrom-Json)
    
  3. 將成員加入 Contributors 群組

    $AzDO_GroupName = "Contributors"
    
    $AzDO_GroupId = ($AzDO_Groups.graphGroups | Where-Object "displayName" -in "$AzDO_GroupName").descriptor
    az devops security group membership add --group-id $AzDO_GroupId --member-id $UserPrincipalName
    

    如果要加入專案管理員群組,可以改成:

    $AzDO_GroupName = "Project Administrators"
    
    $AzDO_GroupId = ($AzDO_Groups.graphGroups | Where-Object "displayName" -in "$AzDO_GroupName").descriptor
    az devops security group membership add --group-id $AzDO_GroupId --member-id $UserPrincipalName
    

    目前預設的專案群組有:

    • Contributors
    • Project Administrators
    • Build Administrators
    • Project Valid Users
    • Readers
    • Release Administrators
    • TeamName Team
  4. 列出使用者目前擁有權限的專案清單

    $AzDO_Projects = $(az devops user show --user $UserPrincipalName -o json | ConvertFrom-Json)
    $AzDO_Projects.projectEntitlements | ForEach-Object -Process {
        # $_.projectRef.id
        $_.projectRef.name
    }
    

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK