在多个作业中查看同一存储库时,Azure yaml相同的关键问题

发布于 2025-02-06 20:31:00 字数 2464 浏览 5 评论 0原文

我有可重复使用的构建模板作业。在我的管道中,每次我想构建新应用程序时,我都会重复使用此模板。在此构建模板内部,它具有内联检查步骤。如果我结帐相同的存储库和分支,就会发生问题。

模板结构

# **pipeline.yaml**
stages:    
- template: templates/group-build.yaml
  parameters:
    branchRef: ${{ variables.branchRef}}


# -----------------------------------------
# **templates/group-build.yaml**
parameters:
  - name: branchRef
    type: string

stages:
 - stage: 'Build'
   displayName: 'Build'
   variables:           
jobs: 
  - template: template/functionapp-build-job.yaml
    parameters:
      branchRef: ${{ parameters.branchRef}}

  - template: template/webapp-build-job.yaml
    parameters:
      branchRef: ${{ parameters.branchRef}}
  

# -----------------------------------------
# **template/functionapp-build-job.yaml**
parameters:
  - name: branchRef
    type: string

jobs:
- template: templates/function/build-job.yaml
  parameters:
    repository: repo
    branchRef: ${{ parameters.branchRef}}
    project: functionapp/function.csproj'


# -----------------------------------------
# **templates/function/build-job.yaml**
parameters:
 - name: repository
   type: string

 - name: project
   type: string

 - name: componentName
   type: string

 - name: branchRef
   type: string

jobs:
  - job: JOB_${{ parameters.componentName}}_BUILD # <- Component is unique
    displayName: Build ${{ parameters.componentName}} Job
    
 steps: 
   // Checking out same repo is not allowed here
   - checkout: git://project/${{ parameters.repository }}@${{ parameters.branchRef}}
   - Other Task here...


# -----------------------------------------
# **template/webapp-build-job.yaml**
# Same structure as function app...

这就是结构

Pipeline
  Stages:
   - Stage:
     Jobs:
       - Job: Web App Build
         Steps:
          - checkout: 'Here I call same repo and branch but different build steps'
       - Job: Function App Build
         Steps:
          - checkout: 'Here I call same repo and branch but different build steps'
   
  

验证问题图像

​https://i.sstatic.net/txbnl.png“ alt =”在此处输入图像描述“>

在管道中添加资源不是我的选择,由于在这里

高度赞赏任何建议或思想来规避此问题。

I have reusable build template job. In my pipeline, I'm reusing this template every time I want to build new application. Inside this build template, it has inline checkout step. Problem occurs if I checkout same repository and branch.

Template structure

# **pipeline.yaml**
stages:    
- template: templates/group-build.yaml
  parameters:
    branchRef: ${{ variables.branchRef}}


# -----------------------------------------
# **templates/group-build.yaml**
parameters:
  - name: branchRef
    type: string

stages:
 - stage: 'Build'
   displayName: 'Build'
   variables:           
jobs: 
  - template: template/functionapp-build-job.yaml
    parameters:
      branchRef: ${{ parameters.branchRef}}

  - template: template/webapp-build-job.yaml
    parameters:
      branchRef: ${{ parameters.branchRef}}
  

# -----------------------------------------
# **template/functionapp-build-job.yaml**
parameters:
  - name: branchRef
    type: string

jobs:
- template: templates/function/build-job.yaml
  parameters:
    repository: repo
    branchRef: ${{ parameters.branchRef}}
    project: functionapp/function.csproj'


# -----------------------------------------
# **templates/function/build-job.yaml**
parameters:
 - name: repository
   type: string

 - name: project
   type: string

 - name: componentName
   type: string

 - name: branchRef
   type: string

jobs:
  - job: JOB_${{ parameters.componentName}}_BUILD # <- Component is unique
    displayName: Build ${{ parameters.componentName}} Job
    
 steps: 
   // Checking out same repo is not allowed here
   - checkout: git://project/${{ parameters.repository }}@${{ parameters.branchRef}}
   - Other Task here...


# -----------------------------------------
# **template/webapp-build-job.yaml**
# Same structure as function app...

This is how it looks like structurally

Pipeline
  Stages:
   - Stage:
     Jobs:
       - Job: Web App Build
         Steps:
          - checkout: 'Here I call same repo and branch but different build steps'
       - Job: Function App Build
         Steps:
          - checkout: 'Here I call same repo and branch but different build steps'
   
  

Validation issue image

validation-issue

enter image description here

Adding resources in pipeline is not my option because refs is being stored in variable group, which is not support to resolve due to limitation of azure yaml as stated here.

Any suggestion or idea to circumvent this issue is highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森罗 2025-02-13 20:31:00

从您的示例中,模板webapp-build-job.yaml和functionApp-build-job.yaml参考相同的yaml:build-job.yaml。

在这种情况下,作业名称(- job:job_build)是相同的密钥,这可能是此问题的根本原因。

要解决此问题,您可以将作业名称定义为一个参数,并在WebApp-build-job.yaml和functionApp-build-job.yaml中分配值。

例如:

build-job.yaml

parameters:
 - name: repository
   type: string

 - name: project
   type: string

 - name: jobname
   type: string

 - name: branchRef
   type: string

jobs:
  - job: ${{ parameters.jobname }}
    displayName: Build Job
    steps: 
    - checkout: git://Artifacts/${{ parameters.repository }}@${{ parameters.branchRef}}

functionapp-build-job.yaml

parameters:
  - name: branchRef
    type: string

jobs:
- template: build-job.yaml
  parameters:
    repository: Repo11
    branchRef: ${{ parameters.branchRef}}
    jobname: test1
    project: functionapp/function.csproj'

webapp-build-job.yaml

parameters:
  - name: branchRef
    type: string

jobs:
- template: build-job.yaml
  parameters:
    repository: Repo11
    branchRef: ${{ parameters.branchRef}}
    jobname: test2
    project: functionapp/function.csproj'

群体建造。 yaml

parameters:
  - name: branchRef
    type: string

stages:
 - stage: 'Build'
   displayName: 'Build'         
   jobs: 
   - template: functionapp-build-job.yaml
     parameters:
      branchRef: ${{ parameters.branchRef}}

   - template: webapp-build-job.yaml
     parameters:
      branchRef: ${{ parameters.branchRef}}

pipeline.yaml

variables: 
  - group: test

stages:    
- template: group-build.yaml
  parameters:
    branchRef: ${{ variables.branchRef}}

From your sample, the template webapp-build-job.yaml and functionapp-build-job.yaml are reference the same yaml:build-job.yaml.

In this case, the job names (- job: JOB_BUILD) are the same key and this can be the root cause of this issue.

To solve this issue, you can define job name as a parameter and assign value in webapp-build-job.yaml and functionapp-build-job.yaml.

For example:

build-job.yaml

parameters:
 - name: repository
   type: string

 - name: project
   type: string

 - name: jobname
   type: string

 - name: branchRef
   type: string

jobs:
  - job: ${{ parameters.jobname }}
    displayName: Build Job
    steps: 
    - checkout: git://Artifacts/${{ parameters.repository }}@${{ parameters.branchRef}}

functionapp-build-job.yaml

parameters:
  - name: branchRef
    type: string

jobs:
- template: build-job.yaml
  parameters:
    repository: Repo11
    branchRef: ${{ parameters.branchRef}}
    jobname: test1
    project: functionapp/function.csproj'

webapp-build-job.yaml

parameters:
  - name: branchRef
    type: string

jobs:
- template: build-job.yaml
  parameters:
    repository: Repo11
    branchRef: ${{ parameters.branchRef}}
    jobname: test2
    project: functionapp/function.csproj'

group-build.yaml

parameters:
  - name: branchRef
    type: string

stages:
 - stage: 'Build'
   displayName: 'Build'         
   jobs: 
   - template: functionapp-build-job.yaml
     parameters:
      branchRef: ${{ parameters.branchRef}}

   - template: webapp-build-job.yaml
     parameters:
      branchRef: ${{ parameters.branchRef}}

Pipeline.yaml

variables: 
  - group: test

stages:    
- template: group-build.yaml
  parameters:
    branchRef: ${{ variables.branchRef}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文