我有一个天蓝色的 DevOps 构建管道,在其中一个阶段我想创建一个服务连接。我想要“kubernetes”和“dockerregistry”类型的服务连接。如何实现?
1。 Azure CLI: 我看到 azure CLI 命令仅创建“azurerm”类型的服务连接和 github。但没有找到任何“Kubernetes”和“dockerregistry”类型的命令。 https://learn.microsoft.com/en-us/cli/azure/devops/service-endpoint?view=azure-cli-latest
2。休息API: 找到了创建服务连接的rest api方法,我尝试给出类型“kubernetes”,但无法弄清楚这里的身份验证。给我错误“无效的客户端 ID”。
3.电源外壳: 没有找到任何与此相关的内容。
你好!
正如我所见,您在
Powershell
中找不到任何方法来做到这一点,我为您创建了一些该场景的示例。
$Organization = "<AzDevOps-Org-Name>"
$PAT = "<PAT>" # <- Should have permissions for Service Connections
$EncodedPAT = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
$Headers = @{
Authorization = "Basic " + $EncodedPAT
"Content-Type" = "application/json"
}
$CreateEndpointsUri = "https://dev.azure.com/$($Organization)/_apis/serviceendpoint/endpoints?api-version=7.1-preview.4"
body
创建 Others
# Docker Registry Connection - Others type
$Body = @{
name = "DockerOthersTest1"
type = "dockerregistry"
url = "https://hub.docker.com/"
authorization = @{
parameters = @{
registry = "https://nameofmyregistry.com"
username = "myusername"
email = "[email protected]"
}
scheme = "UsernamePassword"
}
serviceEndpointProjectReferences = @(
@{
projectReference = @{
id = "<GUID-of-your-project>"
name = "<Name-of-your-project>"
}
name = "DockerOthersTest1" # This will be the name seen in the Service Connections for the project
}
)
} | ConvertTo-Json -Depth 10
# Send the request
Invoke-RestMethod -Uri $CreateEndpointsUri -Headers $Headers -Method Post -Body $Body
body
创建 Azure Container Registry
$Body = @{
name = "DockerAcrTest1"
type = "dockerregistry"
url = "https://hub.docker.com/"
authorization = @{
parameters = @{
loginServer = "<myACRname>.azurecr.io"
role = "8311e382-0749-4cb8-b61a-304f252e45ec" # This is AcrPush role
scope = "<Resource-ID-of-ACR>"
servicePrincipalId = "<Application-ID-of-SPN>"
tenantId = "<Tenant-GUID>"
}
scheme = "ServicePrincipal"
}
data = @{
appObjectId = "<SPN-App-object-ID>"
registryId = "<Resource-ID-of-my-ACR>"
registrytype = "ACR"
spnObjectId = "<Enterprise-SPN-App-object-ID>"
subscriptionId = "<GUID-for-subscription>"
subscriptionName = "<Name-of-my-subscription>"
}
serviceEndpointProjectReferences = @(
@{
projectReference = @{
id = "<GUID-of-your-project>"
name = "<Name-of-your-project>"
}
name = "DockerAcrTest1" # This will be the name seen in the Service Connections for the project
}
)
} | ConvertTo-Json -Depth 10
# Send the request
Invoke-RestMethod -Uri $CreateEndpointsUri -Headers $Headers -Method Post -Body $Body
其他类型
ACR型
我希望这有帮助!祝你好运!