【问题标题】:Azure pipelines: is it mandatory to have azure pipelines and code in same branchAzure 管道:是否必须在同一分支中拥有 azure 管道和代码
【发布时间】:2020-12-01 18:21:24
【问题描述】:

我是天蓝色管道的新手。我已经使用 azure 管道构建作业,并且源代码在同一个分支 dev 中并且运行良好,但是是否可以在不同的分支中拥有 azure 管道和源代码?

如果是这样,请帮助我

另外,如何在 azure 管道中实现分支参数化作业?

【问题讨论】:

    标签: azure azure-devops azure-pipelines


    【解决方案1】:

    感谢您对此的快速回复 来自不同仓库的结帐代码运行良好 但是关于参数化分支名称 我使用了以下但没有工作

    例子

    - name: branch
      displayName: Branch Name
      type: string
      default: dev
      values:
       - dev
       - test
    
    resources:
      repositories:
      - repository: project
        type: git
        name: project
        ref: ${{ parameters.branch }}
    

    【讨论】:

    • 太棒了!感谢您在这里分享您的解决方案,您可以Accept it as an Answer。这可能对阅读此主题的其他社区成员有益,我们可以关闭此主题,谢谢
    【解决方案2】:

    不,这不是必需的。当您为现有文件定义管道时,您可以选择一个分支:

    您甚至可以将管道定义放在不同的存储库中,并从multiple repo pipeline 中受益以实现此目标。

    如果你想参数化管道,你应该看看templates

    # File: templates/npm-with-params.yml
    
    parameters:
    - name: name  # defaults for any parameters that aren't specified
      default: ''
    - name: vmImage
      default: ''
    
    jobs:
    - job: ${{ parameters.name }}
      pool: 
        vmImage: ${{ parameters.vmImage }}
      steps:
      - script: npm install
      - script: npm test
    

    然后就可以这样使用了:

    # File: azure-pipelines.yml
    
    jobs:
    - template: templates/npm-with-params.yml  # Template reference
      parameters:
        name: Linux
        vmImage: 'ubuntu-16.04'
    
    - template: templates/npm-with-params.yml  # Template reference
      parameters:
        name: macOS
        vmImage: 'macOS-10.14'
    
    - template: templates/npm-with-params.yml  # Template reference
      parameters:
        name: Windows
        vmImage: 'vs2017-win2016'
    

    您还可以使用来自不同存储库的模板。假设您在 Contoso/BuildTemplates 存储库中有 common.yml 模板:

    # Repo: Contoso/LinuxProduct
    # File: azure-pipelines.yml
    resources:
      repositories:
        - repository: templates
          type: github
          name: Contoso/BuildTemplates
    
    jobs:
    - template: common.yml@templates  # Template reference
    

    编辑:

    就这个问题而言:

    另外,如何在 azure 管道中实现分支参数化作业?

    这是可能的,但不使用内置功能来获取存储库。您需要的是使用例如 powershell 任务和此命令:

    GIT clone -b <branch>  https://<PAT>@dev.azure.com/Organization/My%20Project/_git/MyRepo
    

    请同时输入您的 YAML checkout: none,因为我们不想通过 standard pipeline task 获取源代码。

    在上述命令中,您必须输入 PAT 令牌。更多关于这方面的信息你会发现here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 2023-03-09
      • 1970-01-01
      • 2023-04-03
      • 2021-08-02
      • 1970-01-01
      相关资源
      最近更新 更多