#azure-devops #azure-pipelines #azure-devops-rest-api #build-definition #azure-repos
#azure-devops #azure-конвейеры #azure-devops-rest-api #определение сборки #azure-репозитории
Вопрос:
Я пытаюсь изменить источник из репозиториев Azure git на GitHub в azure DevOps build с использованием rest api.
Это ответ, который я получаю для репозиториев Azure с использованием rest api определений сборки Azure Devops — GET https://dev.azure.com /{имя_организации}/{имя_проекта}/_apis/build/definitions/{Build_Id}?версия api=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 с помощью postman, скопировав тело ответа GitHub json и добавив postman и попытался вызвать put -https://dev.azure.com /{имя_организации}/{имя_проекта}/_apis/build/definitions/{Build_Id}?версия api=6.0?
Но это не работает
Как я могу добиться этого с помощью script или postman? чего мне здесь не хватает?
Ответ №1:
Как я могу добиться этого с помощью script или postman? чего мне здесь не хватает?
Вы можете скопировать содержимое 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 есть следующие ключевые моменты:
- Поле процесса является обязательным. Вы можете скопировать содержимое из Get Build Definition Rest API.
- Требуется
"id": {DefinitionID}
. "revision": {revisionID}
Вам необходимо ввести действительную ревизию. Это очень важно.
Чтобы получить правильную ревизию, вам необходимо перейти к Azure Pipelines -> Target Build Definition -> History
.
Вам нужно подсчитать, сколько записей обновления. Правильная ревизия — это total number 1
.
Например: на моем скриншоте правильная редакция равна 10 ( 9 1 =10
).