Azure DevOps
在本示例中,我们将使用脚本从 Azure DevOps API 获取数据并将其导入 Port。我们还将在Azure DevOps 和 Port 之间创建 webhook 集成,该集成将导入 "项目"、"资源库"、"工作项 "和 "Pipelines "实体。
Port 配置
创建以下蓝图定义:
Project blueprint
{
"identifier": "azure_devops_project",
"description": "A software catalog for Azure DevOps projects",
"title": "Azure Devops Project",
"icon": "AzureDevops",
"schema": {
"properties": {
"description": {
"title": "Description",
"type": "string"
},
"url": {
"title": "URL",
"type": "string",
"format": "url"
},
"visibility": {
"title": "Visibility",
"type": "string"
},
"last_updated_time": {
"title": "Last Updated Time",
"type": "string",
"format": "date-time"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
Repository blueprint
{
"identifier": "azure_devops_repository",
"description": "A software catalog for Azure Devops repositories",
"title": "Azure Devops Repository",
"icon": "AzureDevops",
"schema": {
"properties": {
"url": {
"title": "URL",
"type": "string",
"format": "url"
},
"default_branch": {
"title": "Default Branch",
"type": "string"
},
"is_disabled": {
"title": "Is Disabled",
"type": "boolean",
"default": false
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"project": {
"title": "Project",
"target": "azure_devops_project",
"required": false,
"many": false
}
}
}
Pipeline blueprint
{
"identifier": "azure_devops_pipeline",
"description": "A software catalog for Azure Devops pipeline",
"title": "Azure Devops Pipeline",
"icon": "AzureDevops",
"schema": {
"properties": {
"url": {
"title": "URL",
"type": "string",
"format": "url"
},
"revision": {
"title": "Revision",
"type": "number"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"project": {
"title": "Project",
"target": "azure_devops_project",
"required": false,
"many": false
}
}
}
Work item blueprint
{
"identifier": "azure_devops_work_item",
"description": "A software catalog for Azure Devops work item",
"title": "Azure Devops Work Item",
"icon": "AzureDevops",
"schema": {
"properties": {
"url": {
"title": "URL",
"type": "string",
"format": "url",
"icon": "DefaultProperty"
},
"revision": {
"title": "Revision",
"type": "number",
"icon": "DefaultProperty"
},
"type": {
"title": "Type",
"type": "string",
"icon": "DefaultProperty"
},
"state": {
"icon": "DefaultProperty",
"title": "State",
"type": "string",
"enum": ["To Do", "Doing", "Done"],
"enumColors": {
"To Do": "blue",
"Doing": "yellow",
"Done": "green"
}
},
"created_date": {
"title": "Created Date",
"type": "string",
"format": "date-time",
"icon": "DefaultProperty"
},
"created_by": {
"icon": "TwoUsers",
"title": "Created By",
"type": "string"
},
"updated_date": {
"title": "Updated Date",
"type": "string",
"format": "date-time",
"icon": "DefaultProperty"
},
"priority": {
"title": "Priority",
"type": "number",
"icon": "DefaultProperty"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"project": {
"title": "Project",
"target": "azure_devops_project",
"required": false,
"many": false
}
}
}
运行 python 脚本
要从 Azure DevOps 账户向 Port 输入数据,请运行以下命令:
export PORT_CLIENT_ID=<ENTER CLIENT ID>
export PORT_CLIENT_SECRET=<ENTER CLIENT SECRET>
export AZURE_DEVOPS_ORG_ID=<ENTER AZURE DEVOPS ORGANIZATION ID>
export AZURE_DEVOPS_APP_PASSWORD=<ENTER AZURE DEVOPS APP PASSWORD>
git clone https://github.com/port-labs/azure-devops-resources.git
cd azure-devops-resources
pip install -r ./requirements.txt
python app.py
查找有关 python 脚本的更多信息here
请按照官方文档了解如何create an azure devops app password 。
Port Webhook 配置
创建以下 webhook 配置using Port's UI
Webhook configuration
- 基本信息 选项卡 - 填写以下详细信息:
1.title:
Azure DevOps Mapper
。 2.标识符:azure_devops_mapper
。 3.描述 :将 Azure DevOps 资源映射到 Port
的 webhook 配置。 4.图标 :AzureDevops
. - 集成配置选项卡--填写以下 JQ 映射:
[
{
"blueprint": "azure_devops_work_item",
"filter": ".body.eventType == \"workitem.created\"",
"entity": {
"identifier": ".body.resource.id | tostring",
"title": ".body.resource.fields.\"System.Title\"",
"properties": {
"revision": ".body.resource.rev",
"url": ".body.resource.url",
"type": ".body.resource.fields.\"System.WorkItemType\"",
"state": ".body.resource.fields.\"System.State\"",
"created_date": ".body.resource.fields.\"System.CreatedDate\"",
"created_by": ".body.resource.fields.\"System.CreatedBy\"",
"updated_date": ".body.resource.fields.\"System.ChangedDate\"",
"priority": ".body.resource.fields.\"Microsoft.VSTS.Common.Priority\""
},
"relations": {
"project": ".body.resourceContainers.project.id"
}
}
},
{
"blueprint": "azure_devops_work_item",
"filter": ".body.eventType == \"workitem.updated\"",
"entity": {
"identifier": ".body.resource.workItemId | tostring",
"title": ".body.resource.revision.fields.\"System.Title\"",
"properties": {
"revision": ".body.resource.rev",
"url": ".body.resource.url",
"type": ".body.resource.revision.fields.\"System.WorkItemType\"",
"state": ".body.resource.revision.fields.\"System.State\"",
"created_date": ".body.resource.revision.fields.\"System.CreatedDate\"",
"created_by": ".body.resource.revision.fields.\"System.CreatedBy\"",
"updated_date": ".body.resource.revision.fields.\"System.ChangedDate\"",
"priority": ".body.resource.revision.fields.\"Microsoft.VSTS.Common.Priority\""
},
"relations": {
"project": ".body.resourceContainers.project.id"
}
}
},
{
"blueprint": "azure_devops_pipeline",
"filter": ".body.eventType | startswith(\"ms.vss-pipelines\")",
"entity": {
"identifier": ".body.resource.run.pipeline.id // .body.resource.pipeline.id | tostring",
"title": ".body.resource.run.pipeline.name // .body.resource.pipeline.name",
"properties": {
"url": ".body.resource.run.pipeline.url // .body.resource.pipeline.name",
"revision": ".body.resource.run.pipeline.revision // .body.resource.pipeline.revision"
},
"relations": {
"project": ".body.resourceContainers.project.id"
}
}
},
{
"blueprint": "azure_devops_repository",
"filter": ".body.eventType == \"git.push\"",
"entity": {
"identifier": ".body.resource.repository.id | tostring",
"title": ".body.resource.repository.name",
"properties": {
"url": ".body.resource.repository.url",
"default_branch": ".body.resource.repository.defaultBranch"
},
"relations": {
"project": ".body.resource.repository.project.id"
}
}
}
]
3.单击页面底部的保存。
在 Azure DevOps 中创建 webhook
- 从你的 Azure DevOps 账户,打开要添加 webhook 的项目。
- 单击左侧边栏上的项目设置。
- 在常规部分,选择左侧边栏上的服务钩子。
- 单击加 + 按钮,为项目创建 webhook。
- 将弹出一个页面。从列表中选择网络钩子,然后点击下一步。
- 在触发器下,选择要接收 webhook 通知的事件类型。示例 webhook 配置支持以下事件:
1.代码推送
2.运行状态改变
3.运行任务状态已更改
4.运行阶段状态已更改
5.创建工作项
6.更新工作项
7.保留过滤器部分不变,然后单击下一步。
8.在最后一页(操作设置),在
URL
文本框中输入您在 Port 中创建 webhook 配置后收到的 webhookURL
的值。 9.测试您的 Webhook 订阅,然后单击完成。
请关注this documentation ,了解有关 Azure DevOps 中 webhook 事件的更多信息。
完成!Azure DevOps 中的版本库、工作项或管道发生的任何更改都会触发指向 Port 提供的 webhook URL 的 webhook 事件。 Port 将根据映射解析事件并相应地更新目录实体。