Azure DevOps YAML管道-他们可以从存储库中提取脚本吗?

时间:2020-05-06 14:28:25

标签: azure-devops azure-pipelines azure-devops-yaml

在我发布的图形版本中,我连接到“ Azure Repo”以从中提取脚本,而不是构建的工件

在YAML管道中可以这样做吗?到目前为止,还不清楚,谢谢。

回购中有很多脚本,因此不需要构建或打包为zip / drop包。

enter image description here

3 个答案:

答案 0 :(得分:2)

是的,抱歉,我不好。对的,这是可能的。跟随doc

如果您的管道在另一个存储库中有模板,或者您想对需要服务连接的存储库使用多仓库签出,则必须让系统知道该存储库。使用存储库关键字可以指定外部存储库。

resources:
  repositories:
  - repository: string  # identifier (A-Z, a-z, 0-9, and underscore)
    type: enum  # see the following "Type" topic
    name: string  # repository name (format depends on `type`)
    ref: string  # ref name to use; defaults to 'refs/heads/master'
    endpoint: string  # name of the service connection to use (for types that aren't Azure Repos)

答案 1 :(得分:2)

资源是作为管道一部分使用的任何外部服务。资源的一个示例是另一个产生以下内容的CI / CD管道:

resources:
  pipelines: [ pipeline ]
  repositories: [ repository ]
  containers: [ container ]
  • Azure Pipelines或Jenkins之类的工件。
  • 代码存储库,例如GitHub,Azure Repos或Git。
  • Azure容器注册表或Docker等容器映像注册表 集线器。

YAML中的资源表示管道,容器,存储库和类型的源。有关参考资料的更多信息,请参见here

答案 2 :(得分:0)

@Hugh Lin-MSFT @Krzysztof Madej

我的Azure DevOps GIT存储库称为“ AZDO_Scripts”(同一项目的所有部分),并且具有类似这样的结构...

/Scripts/AzureCLI/ResourceGroup/Provision_ResourceGroup_withTags.ps1

我的YAML现在就像这样...

name: $(date:yyyyMMdd)$(rev:.r)-$(SourceBranchName)

trigger:
- master

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

resources:
  repositories:
  - repository: commonscripts
    type: git
    name: AZDO_Scripts

stages:
- stage: Test
  variables:
    - name: resourcegroup
      value: 'rg-testthescript'
    - name: location
      value: 'WestEurope'
    - name: environmenttag
      value: 'Test'
  jobs:
    - job : TestJob
      pool:
        vmImage: 'windows-latest'
      steps:
      - task: AzureCLI@2
        inputs:
          azureSubscription: 'My-Azure-Sub-ServiceConnection'
          scriptType: 'ps'
          scriptLocation: 'scriptPath'
          scriptPath: 'Scripts/AzureCLI/ResourceGroup/Provision_ResourceGroup_withTags.ps1@commonscripts'
          arguments: '-resourcegroup $(resourcegroup) -location $(location) -environmenttag $(environmenttag)'

我需要在scriptPath:语句中引用该脚本吗? (从底部第二行)

scriptPath: 'Scripts/AzureCLI/ResourceGroup/Provision_ResourceGroup_withTags.ps1@commonscripts'
相关问题