我现在将大部分经典构建管道转换为 yaml。yaml 转换工具 devop 基本上将我的经典构建管道任务视为单独的 yaml 任务。所以现在我有一份大约有 8 项任务的工作。
在学习 yaml 时,我看到有些会创建多个作业,有些甚至会创建多个阶段。对我来说,阶段似乎适合不同的部署环境(开发、QA、UAT 等)。但我不确定什么时候应该使用多个作业?
假设我在一个存储库中有两个解决方案,并且想要构建这两个解决方案,并且我的工件将包含这两个解决方案的 dll。对于每个解决方案,我的任务将是构建、运行单元测试并打包 dll。
我可以将所有这些都放在一项工作中,因此这将是一步一步完成的连续任务。或者我可以创建两个作业,每个作业处理一个解决方案的构建。但与一项工作相比,使用多项工作有什么好处吗?微软似乎允许你的代理并行运行两个作业(理论上它会更快),但他们会为此收费。
谢谢
任何人都可以解释 Azure YAML 架构触发器中的 Batch 的作用吗?
MSFT网站上唯一的解释是
batch changes if true; start a new build for every push if false (default)
我不太清楚
azure devops azure-devops azure-pipelines azure-yaml-pipelines
我想定义部署作业(通过模板),但是运行我的 azure 管道时,显示以下错误:
job-deploy.yml@templates:预期映射结束
我的问题出在哪里?
以下模板称为:
job-deploy.yml@templates: Expected mapping end
deployment azure-devops azure-pipelines azure-yaml-pipelines
在模板管道中,您不能放置任何触发器语句,例如trigger: noneMicrosoft文档中指定的禁用 ci 触发器,所以我想知道您如何防止每次更新这些管道或同一分支中的任何其他 yaml 文件时执行这些管道?
azure-devops azure-pipelines azure-pipelines-yaml azure-yaml-pipelines azure-devops-pipelines
在我运行任何其他任务 dist 文件夹之前,构建过程中生成的文件夹似乎已被删除。
trigger:
- master
pool: default
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install -g @angular/cli
npm install
ng build --prod
displayName: 'npm install and build'
#i added this task and it seems like the node_modules and the dist
#folder that was generated during the build are not getting copied to the (a)directory
#only the source code get copied. it seems like the folders are getting
#deleted even before the #PublishPipelineArtifact@1 …Run Code Online (Sandbox Code Playgroud) 我有一个包含不同密钥(例如 Key1、Key2、Key3)的 Azure Key Vault。在某些在一个管道任务中动态读取的设置中,我有一个值来说明要使用哪个键(让 KeyName 变量为“Key2”)。如何读取管道中Key2的秘密值?
我尝试过不同的组合,但没有一个对我有用。
测试管道编号 1 - 使用连接到 Key Vault 的组变量(为了更简单,这里的 KeyName 是静态的,但实际上,它是在管道期间通过 powershell 脚本设置的):
jobs:
- job: JobA
variables:
- group: KeyVaultGroup #Key vault have secret values "Key1,Key2,Key3..."
- name: KeyName
value: Key2
- name: MyValue
value: $[ variables[variables.KeyName] ]
steps:
- powershell: |
Write-Host "Var1 $($env:VARENV1)"
Write-Host "Var2 $($env:VARENV2)"
env:
VarEnv1: $(MyValue)
VarEnv2: $($(KeyName))
Run Code Online (Sandbox Code Playgroud)
结果是:
Var1
Var2 $(Key2)
Run Code Online (Sandbox Code Playgroud)
MyValue 不起作用,因为在加载密钥保管库变量之前会评估该变量。当在管道期间设置 KeyName 时,它也将不起作用(但这可以通过使用单独的作业并使用输出变量来设置 KeyName 来解决 - 就像测试示例 2 中一样)。表达式 $($(KeyName)) 不起作用,因为它不会递归扩展变量(bug?)。
当使用 AzureKeyVault 任务读取 Key …
azure-keyvault azure-devops azure-pipelines azure-yaml-pipelines
我正在运行管道,执行一个简单的任务来安装 git 并通过以下命令检查版本tasks。
一切都运行良好,直到我使用相同的 yaml 文件创建另一个临时管道以进行一些额外的测试和开发。
我没有对 yaml 文件进行任何更改,该文件仍然以绿色运行,具有相同的任务。
但是新管道中的执行任务失败并出现“意外”错误
steps:
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: "5.10.x"
- task: gitversion/execute@0
displayName: Determine Version
inputs:
useConfigFile: true
configFilePath: ./gitversion.yml
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
Command: dotnet-gitversion /agent/_work/26/s /output json /output buildserver /config /agent/_work/26/s/gitversion.yml
/opt/hostedtoolcache/GitVersion.Tool/5.10.3/x64/dotnet-gitversion /agent/_work/26/s /output json /output buildserver /config /agent/_work/26/s/gitversion.yml
ERROR [09/20/22 12:54:22:24] An unexpected error occurred:
System.NullReferenceException: Object reference not set to an instance of an object.
at LibGit2Sharp.Core.Handles.ObjectHandle.op_Implicit(ObjectHandle handle) in /_/LibGit2Sharp/Core/Handles/Objects.cs:line 509
at LibGit2Sharp.Core.Proxy.git_commit_author(ObjectHandle obj) in /_/LibGit2Sharp/Core/Proxy.cs:line …Run Code Online (Sandbox Code Playgroud) 在 Azure Devops“经典”管道中,管道选项菜单中有一个部分,您可以在其中打开一项功能,以在管道失败时自动创建工作项。但是,在新的 YAML 管道中,选项菜单中不存在此功能。此选项是否仍然以某种方式可用,或者 YAML 管道不支持它?
我有以下管道模板,我想用它来根据输入参数有条件地执行阶段stages。
parameters:
- name: dryRun
default: false
type: boolean
- name: path
type: string
default: terraform
- name: stages
type: object
default:
- test
- prod
stages:
- stage:
pool:
vmImage: 'ubuntu-latest'
displayName: "Deploy to test"
condition: in('test', ${{ parameters.stages }})
jobs:
- template: terraform-job.yaml
parameters:
stage: test
path: ${{ parameters.path }}
dryRun: ${{ parameters.dryRun }}
- stage:
pool:
vmImage: 'ubuntu-latest'
displayName: "Deploy to production"
condition: in('prod', '${{ join(', ', parameters.stages) }}')
jobs:
- template: terraform-job.yaml
parameters:
stage: …Run Code Online (Sandbox Code Playgroud) 我在 git 存储库中有这样的项目(文件夹)结构:
/src
/src/Sample.Backend.Common
/src/Sample.Backend.Common.Tests
/src/Sample.Backend.Common.Domain
/src/Sample.Backend.Common.Domain.Tests
/src/Sample.Backend.Pricing.Abstractions
/src/Sample.Backend.Pricing.Domain
/src/Sample.Backend.Pricing.Domain.Tests
/src/Sample.Backend.Pricing.Persistence
/src/Sample.Backend.Pricing.Persistence.Tests
/src/Sample.Backend.Accounting.Abstractions
/src/Sample.Backend.Accounting.Domain
/src/Sample.Backend.Accounting.Domain.Tests
/src/Sample.Backend.Accounting.Persistence
/src/Sample.Backend.Accounting.Persistence.Tests
/src/Sample.Backend.Api
/src/Sample.Common
/src/Sample.Frontend.Common
/src/Sample.Frontend.Web
/src/Sample.Tests.Common
Run Code Online (Sandbox Code Playgroud)
(示例已简化,实际上有更多的项目/文件夹。)
我想要不同的部分有不同的管道。例如,只要在任何后端master项目的分支中提交任何文件,就会触发管道。像这样的东西:
trigger:
branches:
include:
- master
paths:
include:
- src/Sample.Backend.*
- src/Sample.Common
- src/Sample.Tests.Common
Run Code Online (Sandbox Code Playgroud)
问题是,该过滤器src/Sample.Backend.*不起作用。我必须添加每个后端文件夹的确切名称才能使其正常工作。我可以使用exclude,但我有同样的问题 - 还有很多其他项目,我必须将它们全部命名。
我发现不支持通配符:https://github.com/MicrosoftDocs/azure-devops-docs/issues/397#issuecomment-422958966
还有其他方法可以达到相同的结果吗?