Как обновить источник определения сборки Azure DevOps из репозиториев Azure в GitHub с помощью rest api

Я пытаюсь изменить источник с репозитория azure git на GitHub в сборке Azure DevOps с помощью rest api.

Это ответ, который я получаю для репозиториев azure с использованием определений сборки azure Devops rest api - GET https://dev.azure.com/%7Borg_name%7D/%7Bproject_name%7D/_apis/build/definitions/%7BBuild_Id%7D?Api-version=6.0?

"repository": {
    "properties": {
        "cleanOptions": "0",
        "labelSources": "0",
        "labelSourcesFormat": "$(build.buildNumber)",
        "reportBuildStatus": "true",
        "gitLfsSupport": "false",
        "skipSyncSource": "false",
        "checkoutNestedSubmodules": "false",
        "fetchDepth": "0"
    },
    "id": "xxxx",
    "type": "TfsGit",
    "name": "{repo_name}",
    "url": "https://dev.azure.com/{org_name}/{project_name}/_git/{repo_name}",
    "defaultBranch": "refs/heads/master",
    "clean": "false",
    "checkoutSubmodules": false
},

Если вручную я меняю источник с репозиториев Azure на GitHub, это будет ответ json, который я получаю для репозитория GitHub -

  "repository": {
    "properties": {
        "apiUrl": "https://api.github.com/repos/{github_id}/{repo_name}",
        "branchesUrl": "https://api.github.com/repos/{github_id}/{repo_name}/branches",
        "cloneUrl": "https://github.com/{github_id}/{repo_name}.git",
        "connectedServiceId": "xxxxxxx",
        "defaultBranch": "master",
        "fullName": "{github_id}/{repo_name}",
        "hasAdminPermissions": "True",
        "isFork": "False",
        "isPrivate": "False",
        "lastUpdated": "10/16/2019 17:28:29",
        "manageUrl": "https://github.com/{github_id}/{repo_name}",
        "nodeId": "xxxxxx",
        "ownerId": "xxxxx",
        "orgName": "{github_id}",
        "refsUrl": "https://api.github.com/repos/{github_id}/pyapp/git/refs",
        "safeRepository": "{github_id}/pyapp",
        "shortName": "{repo_name}",
        "ownerAvatarUrl": "https://avatars2.githubusercontent.com/u/xxxxx?v=4",
        "archived": "False",
        "externalId": "xxxxxx",
        "ownerIsAUser": "True",
        "checkoutNestedSubmodules": "false",
        "cleanOptions": "0",
        "fetchDepth": "0",
        "gitLfsSupport": "false",
        "reportBuildStatus": "true",
        "skipSyncSource": "false",
        "labelSourcesFormat": "$(build.buildNumber)",
        "labelSources": "0"
    },
 "id": "{github_id}/{repo_name}",
        "type": "GitHub",
        "name": "{github_id}/{repo_name}",
        "url": "https://github.com/{github_id}/{repo_name}.git",
        "defaultBranch": "master",
        "clean": "false",
       "checkoutSubmodules": false

Я попытался изменить репозиторий azure на github с помощью почтальона, скопировав тело ответа GitHub json и добавив почтальона, и попытался вызвать put -https: //dev.azure.com/ {org_name} / {project_name} / _apis / build / definitions / {Build_Id}? Api-version = 6.0?

Но это не работает

Как я могу добиться этого с помощью скрипта или почтальона? что мне здесь не хватает?

введите описание изображения здесь

введите описание изображения здесь




Ответы (1)


Как я могу добиться этого с помощью скрипта или почтальона? что мне здесь не хватает?

Вы можете скопировать содержимое Get Build Definition API.

Вот мой пример:

URL:

PUT https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/build/definitions/{DefinitionID}?api-version=5.0-preview.6

Образец тела запроса:

{
    "process": {
        "phases": [
            {
                "steps": [

                ],
                "name": "Phase 1",
                "refName": "Phase_1",
                "condition": "succeeded()",
                "target": {
                    "executionOptions": {
                        "type": 0
                    },
                    "allowScriptsAuthAccessOption": false,
                    "type": 1
                },
                "jobAuthorizationScope": "projectCollection",
                "jobCancelTimeoutInMinutes": 1
            }
        ],
        "type": 1
    },
    "repository": {
        "properties": {
            "cleanOptions": "0",
            "labelSources": "0",
            "labelSourcesFormat": "$(build.buildNumber)",
            "reportBuildStatus": "true",
            "gitLfsSupport": "false",
            "skipSyncSource": "false",
            "checkoutNestedSubmodules": "false",
            "fetchDepth": "0"
        },
         "id": "{github_id}/{repo_name}",
        "type": "GitHub",
        "name": "{github_id}/{repo_name}",
        "url": "https://github.com/{github_id}/{repo_name}.git",
        "defaultBranch": "master",
        "clean": "false",
        "checkoutSubmodules": false
    },
    "id": {DefinitionID},
    "revision": {revisionID},
    "name": "definitionCreatedByRESTAPI",
    "type": "build",
    "queueStatus": "enabled"
}

В Reuqest Body есть следующие ключевые моменты:

  1. Поле Процесс является обязательным. Вы можете скопировать контент из Get Build Definition Rest API.

  2. "id": {DefinitionID} является обязательным.

  3. "revision": {revisionID} Вам необходимо ввести действительную версию. Это очень важно.

Чтобы получить правильную версию, вам нужно перейти к Azure Pipelines -> Target Build Definition -> History.

введите описание изображения здесь

Вам нужно посчитать, сколько записей Обновить. Правильная версия - total number + 1.

Например: на моем скриншоте правильная версия - 10 (9+1 =10).

person Kevin Lu-MSFT    schedule 27.11.2020