lek*_*kso 0 azure-devops azure-pipelines azure-yaml-pipelines
我的 Azure DevOps 管道使用来自两个不同存储库的 yaml 模板,其配置如下。
模板存储库作为根模板中的资源被引用。我没有找到只检出模板存储库一次然后在所有管道阶段使用模板和脚本的方法。现在,我必须在需要使用其他模板或脚本的每个阶段手动克隆模板存储库。在每个阶段结束时,Azure Devops 会清除克隆的存储库。是否有一种简单的方法可以只检出模板 repo 一次,或者以其他方式从子阶段引用其资源?
我不确定,因为您没有显示 YAML 文件,但是您是否使用了结帐步骤:
resources:
repositories:
- repository: devops
type: github
name: kmadof/devops-templates
endpoint: kmadof
steps:
- checkout: self
- checkout: devops
- script: |
echo $(Build.SourcesDirectory)
ls $(Build.SourcesDirectory) *
- template: templates/template.yaml@devops
parameters:
repo: devops-templates
Run Code Online (Sandbox Code Playgroud)
上面的脚本检查两个 repos。在devops-templates
我有在主构建 yaml 文件(位于self
repo 中)中使用的模板。
也请看这里
编辑
我在这方面做了一些工作,并尝试了一些东西。让我描述文件之间的第一个关系:
而且您不必实际签出模板存储库,因为在运行时所有模板都已完成并创建了构建计划。如果您要运行一些脚本(例如 powershell 脚本),您只需要签出模板存储库。这是我的 yaml 文件:
构建.yaml
resources:
repositories:
- repository: devops
type: github
name: kmadof/devops-templates
endpoint: kmadof
stages:
- template: templates/start.yaml@devops
parameters:
repo: devops-templates
buildSteps:
- checkout: self
- checkout: devops
- bash: echo Test #Passes
displayName: succeed
- bash: echo "Test"
displayName: succeed
Run Code Online (Sandbox Code Playgroud)
开始.yaml
# File: start.yml
parameters:
- name: repo # defaults for any parameters that aren't specified
default: ''
- name: buildSteps # the name of the parameter is buildSteps
type: stepList # data type is StepList
default: [] # default value of buildSteps
stages:
- stage: secure_buildstage
pool: Hosted VS2017
jobs:
- template: process.yaml
parameters:
pool: # this parameter is called `pool`
vmImage: ubuntu-latest # and it's a mapping rather than a string
- job: secure_buildjob
steps:
- script: echo This happens before code
displayName: 'Base: Pre-build'
- script: echo Building
displayName: 'Base: Build'
- ${{ each step in parameters.buildSteps }}:
- ${{ each pair in step }}:
${{ pair.key }}: ${{ pair.value }}
- script: echo This happens after code
displayName: 'Base: Signing'
Run Code Online (Sandbox Code Playgroud)
进程.yaml
# File: start.yml
parameters:
- name: repo # defaults for any parameters that aren't specified
default: ''
- name: buildSteps # the name of the parameter is buildSteps
type: stepList # data type is StepList
default: [] # default value of buildSteps
stages:
- stage: secure_buildstage
pool: Hosted VS2017
jobs:
- template: process.yaml
parameters:
pool: # this parameter is called `pool`
vmImage: ubuntu-latest # and it's a mapping rather than a string
- job: secure_buildjob
steps:
- script: echo This happens before code
displayName: 'Base: Pre-build'
- script: echo Building
displayName: 'Base: Build'
- ${{ each step in parameters.buildSteps }}:
- ${{ each pair in step }}:
${{ pair.key }}: ${{ pair.value }}
- script: echo This happens after code
displayName: 'Base: Signing'
Run Code Online (Sandbox Code Playgroud)
另一个模板.yaml
parameters:
- name: 'pool'
type: object
default: {}
jobs:
- job: build
pool: ${{ parameters.pool }}
steps:
- template: another-template.yaml
parameters:
repo: devops-templates
Run Code Online (Sandbox Code Playgroud)
构建作业使用来自 devops-template repo 的模板,但我不在此作业中检出 repo。
您可能想知道为什么我们不能对每个构建进行一次结帐。这是因为每个作业可以运行不同的代理。
这里有几个链接:
最后一点,当您从该存储库模板调用文件时,您确实需要使用模板检出存储库。例如:
parameters:
- name: repo # defaults for any parameters that aren't specified
default: ''
steps:
- pwsh: Write-Host 'Hello form another template'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3245 次 |
最近记录: |