Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure devops 有没有办法在Azure DevOps中编写重复任务的脚本?_Azure Devops - Fatal编程技术网

Azure devops 有没有办法在Azure DevOps中编写重复任务的脚本?

Azure devops 有没有办法在Azure DevOps中编写重复任务的脚本?,azure-devops,Azure Devops,每次在项目中创建新的GIT存储库时,我们都要执行许多任务,我想知道是否有办法编写脚本(PowerShell或任何其他方法)来完成这些任务。例如,每次创建新回购协议时,我们都会遵循这些步骤 创建新的GIT回购协议 创建一个生成管道,以便在运行期间进行生成验证 拉取请求 向Master添加分支策略,包括使用上述生成验证生成的步骤 为发布创建生成管道 创建发布管道 有没有办法在Azure DevOps中编写重复任务的脚本 当然可以!正如Daniel在评论中所说,只要使用RESTAPI就可以实现所有这些

每次在项目中创建新的GIT存储库时,我们都要执行许多任务,我想知道是否有办法编写脚本(PowerShell或任何其他方法)来完成这些任务。例如,每次创建新回购协议时,我们都会遵循这些步骤

  • 创建新的GIT回购协议
  • 创建一个生成管道,以便在运行期间进行生成验证 拉取请求
  • 向Master添加分支策略,包括使用上述生成验证生成的步骤
  • 为发布创建生成管道
  • 创建发布管道
  • 有没有办法在Azure DevOps中编写重复任务的脚本

    当然可以!正如Daniel在评论中所说,只要使用RESTAPI就可以实现所有这些。但是,由于您想要实现的步骤很少,因此脚本可能不太复杂


    • 创建新的GIT回购协议
    如果您还想使用API完成此步骤,则需要3个步骤来完成此步骤(因为此步骤未在文档中记录,我将非常详细地描述):

    步骤1:创建导入存储库的验证

    POST https://dev.azure.com/{org name}/{project name}/_apis/git/import/ImportRepositoryValidations?api-version=5.2-preview.1 
    
    请求机构:

    {
      "gitSource":
         {
          "url":"${ReposURL}",
          "overwrite":false
         },
        "tfvcSource":null,
        "username":"$(username}"/null,
        "password":"${pw}"/"${PAT}"/null
    }
    
    {
      "name":"${ReposName}",
      "project":
      {
        "name":"{project name}",
        "id":"{this project id}"
      }
    }
    
    {
      "parameters":
      {
       "deleteServiceEndpointAfterImportIsDone":true,
       "gitSource":
        {
         "url":"${ReposURL}",
         "overwrite":false
        },
        "tfvcSource":null,
        "serviceEndpointId":null
    }
    }
    
    步骤2:创建新的回购名称

    POST https://dev.azure.com/{org name}/{project name}/_apis/git/Repositories?api-version=5.2-preview.1
    
    请求机构:

    {
      "gitSource":
         {
          "url":"${ReposURL}",
          "overwrite":false
         },
        "tfvcSource":null,
        "username":"$(username}"/null,
        "password":"${pw}"/"${PAT}"/null
    }
    
    {
      "name":"${ReposName}",
      "project":
      {
        "name":"{project name}",
        "id":"{this project id}"
      }
    }
    
    {
      "parameters":
      {
       "deleteServiceEndpointAfterImportIsDone":true,
       "gitSource":
        {
         "url":"${ReposURL}",
         "overwrite":false
        },
        "tfvcSource":null,
        "serviceEndpointId":null
    }
    }
    
    步骤3:导入回购

    POST https://dev.azure.com/{org name}/{project name}/_apis/git/repositories/{the new repos name you create just now}/importRequests?api-version=5.2-preview.1
    
    请求机构:

    {
      "gitSource":
         {
          "url":"${ReposURL}",
          "overwrite":false
         },
        "tfvcSource":null,
        "username":"$(username}"/null,
        "password":"${pw}"/"${PAT}"/null
    }
    
    {
      "name":"${ReposName}",
      "project":
      {
        "name":"{project name}",
        "id":"{this project id}"
      }
    }
    
    {
      "parameters":
      {
       "deleteServiceEndpointAfterImportIsDone":true,
       "gitSource":
        {
         "url":"${ReposURL}",
         "overwrite":false
        },
        "tfvcSource":null,
        "serviceEndpointId":null
    }
    }
    
    在这些脚本中,您可以在Variable选项卡中设置变量,然后使用
    ${}
    在脚本中获取它们


    • 在拉取请求期间为生成验证创建生成管道
    这一步您最好手动完成,因为您可以配置更多关于任务的信息,并使用UI触发。如果仍要使用API,请参阅此文档:。有详细的样品,你可以试试


    向Master添加分支策略,包括使用上述生成验证生成的步骤

    此API仍将记录在文档中:。只需参考它,并确保使用正确的
    策略类型
    和相应的
    构建定义ID


    • 为发布创建生成管道
    这仍然建议您手动完成,与您提到的步骤3相同


    创建发布管道

    请参阅此文档:

    注意:对于一些将被多次使用的参数,您可以将其设置为变量。对于需要从上一个API响应中获取的参数,您可以定义一个变量来获取其值,然后将此变量传递到下一个API中使用。例如:

    $resultT= $result.Headers.ETag
    Write-Host  "##vso[task.setvariable variable=etag;]$resultT"
    

    现在,您可以在下一个API中直接使用
    $(etag)

    是。看看RESTAPI文档。嗨,现在情况如何?下面的答案对你有帮助吗?如果是,您可以接受,这样其他SO用户将能够看到解决方案是否有效。如果您仍然面临一些问题,请留下评论,以便我们仍然可以帮助您。