我们如何使用azure devops管道打印团队通道中的用户ID?

问题描述 投票:0回答:1

我需要在 GCP 存储桶中更新文件并触发 azure CI 后立即在团队频道中打印用户 ID(CI 触发的用户 ID)。

有人可以建议我如何继续吗?

请找到下面我尝试过的代码:

def get_triggered_user_id():
    organization_url = "https://dev.azure.com/{organisation_name}/"
    project_name = os.environ.get('ComponentName')
    build_id = os.environ.get('BUILD_BUILDID')  # Assuming this environment variable is available

    api_url = f"{organization_url}{project_name}/_apis/build/builds/{build_id}?api-version=6.0"
    headers = {
        'Authorization': f'Basic {os.environ["SYSTEM_ACCESSTOKEN"]}'  ##Here the id is not generating in my logs in devops pipeline
    }

    response = requests.get(api_url, headers=headers)
    response.raise_for_status()

    triggering_user_id = response.json().get('requestedFor').get('id')
    return triggering_user_id
python google-cloud-platform azure-devops microsoft-teams azure-webhooks
1个回答
0
投票

根据您的要求,您需要将用户 ID 打印到 Microsoft 团队频道。

为了满足您的要求,您可以使用 Microsoft Teams 中的传入 Webhook。

步骤如下:

1.在 Microsoft Teams -> 频道中创建 webhook

(a) 导航到要添加 Webhook 的通道并选择 (•••) 连接器。

(b) 搜索 Incoming Webhook,然后添加它。

(c) 单击“配置”并为您的 Webhook 提供名称。

(d) 复制 Webhook URL

2.我们可以安装pymsteams来连接webhook。

安装pymsteams

pip install pymsteams

3.使用以下Python脚本示例

import pymsteams
myTeamsMessage = pymsteams.connectorcard("<Microsoft Webhook URL>")
myTeamsMessage.text("useridinfo")
myTeamsMessage.send()

更详细的信息,可以参考这个文档:Teams传入Webhook

另一方面,您也可以考虑直接使用 Azure Pipelines Teams Integration 连接到 MS 团队中的 Azure DevOps。

© www.soinside.com 2019 - 2024. All rights reserved.