Azure Pipelines 中的单个 CI 和批量 CI 有什么区别?
batch它与 Azure Pipelines YAML 中的选项有何关系trigger?
trigger:
batch: 'true'
branches:
include:
- main
Run Code Online (Sandbox Code Playgroud) 考虑以下管道片段,这是模板的一部分。
- task: Bash@3
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=AppType;]WebJob"
echo "##[debug] AppType set to WebJob"
# This works, using the task condition
- task: DotNetCoreCLI@2
condition: eq(variables['AppType'], 'WebJob')
displayName: 'net publish for WebJob'
inputs:
command: 'publish'
# This doesn't work, using the conditional insertion, index syntax
- ${{ if eq(variables['AppType'], 'WebJob') }}:
- task: DotNetCoreCLI@2
displayName: 'net publish for WebJob'
inputs:
command: 'publish'
# This also doesn't work, using the conditional insertion, property dereference syntax
- ${{ …Run Code Online (Sandbox Code Playgroud) 我希望在提交到同一 Azure 项目内的另一个存储库后运行一个存储库的管道。
我的管道定义:
resources:
repositories:
- repository: SupDevA
name: Sup.Dev.A
type: git
ref: test
trigger:
branches:
include:
- test
steps:
- script: 'echo test'
- template: dummy-template.yml@SupDevA
parameters:
text: 'testing if the dummy templates is executed'
Run Code Online (Sandbox Code Playgroud)
Sup.Dev.A 是在分支上进行提交时应触发我的管道的存储库的名称test。但是当我在分支测试上创建提交时,触发器不会触发。
两个存储库都在同一个项目中,我错过了什么吗?该代码基于MS文档https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
编辑:添加了 -template 部分,因此很明显,当手动触发时,管道会成功执行资源存储库中的模板
我们有一个场景,一旦我们手动取消 Azure DevOps 中的管道,我们需要终止特定进程 (exe)。我们想知道如何在 YAML 取消后触发任务来实现这一目标。
有没有比让脚本抛出错误更好/更干净/更惯用的方法来退出基于 .yaml 的 Azure Pipeline?
例如,这可行,但感觉很笨拙:
- task: PowerShell@2
displayName: "Exit"
inputs:
targetType: 'inline'
script: |
throw 'Exiting';
Run Code Online (Sandbox Code Playgroud) 希望你们一切都好!
我需要问一个关于azure devops的问题,我已经阅读了文档,但是我没有找到解决这些疑问的方法
我有 X、Y 和 Z 项目,并在 X 项目中在管道 >> Libray中创建一组称为常规的变量,我希望与 Y 和 Z 管道共享,在配置该组时我启用了选项“允许访问所有管道”。
在 Y 和 Z 管道的 YAML 中,我进行了以下配置:**变量:
运行管道时,他返回一个授权请求,甚至单击授权,根据下面的打印:
There was a resource authorization issue:
"An error occurred while loading the YAML build pipeline.
Variable group was not found or is not authorized for use.
For authorization details, refer to https://aka.ms/yamlauthz."
Run Code Online (Sandbox Code Playgroud)
我的问题是,有没有办法在不同用途的管道之间共享变量,如果有的话,您能给我发送一些可以帮助我配置这个的文档吗?
我们使用 dotnet test --no-build 在 PR/CI 构建期间运行单元测试:
- task: DotNetCoreCLI@2
${{ if eq(parameters.shortName, '') }}:
displayName: "Test ${{ parameters.name }}"
${{ if ne(parameters.shortName, '') }}:
displayName: "Test ${{ parameters.shortName }}"
inputs:
command: "test"
projects: ${{ parameters.path }}
${{ if eq(parameters.testFilter, '') }}:
arguments: $(TestBinLogArg) -c $(BuildConfiguration) --no-build ${{ parameters.commonFlags }} ${{ parameters.moreTestArgs }} --filter ${{ parameters.unitTestFilter }}
${{ if ne(parameters.testFilter, '') }}:
arguments: $(TestBinLogArg) -c $(BuildConfiguration) --no-build ${{ parameters.commonFlags }} ${{ parameters.moreTestArgs }} --filter (${{ parameters.unitTestFilter }})&(${{ parameters.testFilter }})
publishTestResults: …Run Code Online (Sandbox Code Playgroud) unit-testing azure-devops azure-pipelines azure-pipelines-yaml
我在尝试在另一个阶段使用在一个阶段中创建的变量时遇到了一些问题,并设法找到了各种新旧文章来描述如何完成此操作。识别新语法的最新文章/帖子
$[stageDependencies.{stageName}.{jobName}.outputs['{stepName}.{variableName}']
像这样使用:
variables:
myVariable: $[stagedependencies.CreateStageVarStage.CreateStageVarJob.outputs['SetValueStep.VariableFromFirstStage']]
Run Code Online (Sandbox Code Playgroud)
在您需要使用作业模板之前,这非常有效。
我在网上找到的示例都没有涵盖模板的情况。他们只是演示了同一个 yaml 文件中的多个阶段如何获取该值。
语法取决于能否将表达式放入变量中。不幸的是,当您在作业中使用模板时,无法声明变量并将其作为参数传递,从而导致其无法求值。
- stage: UseJobTemplateStage
displayName: 'Use Job Template Stage'
dependsOn: CreateStageVarStage
jobs:
- template: templates/job-showstagevars.yml
parameters:
ValueToOutput: $[ stagedependencies.CreateStageVarStage.CreateStageVarJob.outputs['SetValueStep.VariableFromFirstStage'] ]
Run Code Online (Sandbox Code Playgroud)
在这个片段中,它按原样出现。该值不会被替换。
理论上,您可以将作业设置为使表达式存在于变量块中,但这种硬编码破坏了模板的主要优点之一。
在 Azure DevOps Pipelines 中跨阶段共享变量
Azure DevOps 发行说明 - sprint 168
我在尝试在 yaml 文件中使用以下语法分配变量时遇到问题。以下代码取自 Microsoft 文档中定义变量的理解变量语法部分:
variables:
- name: one
value: initialValue
steps:
- script: |
echo ${{ variables.one }} # outputs initialValue
echo $(one)
displayName: First variable pass
- bash: echo '##vso[task.setvariable variable=one]secondValue'
displayName: Set new variable value
- script: |
echo ${{ variables.one }} # outputs initialValue
echo $(one) # outputs secondValue
displayName: Second variable pass
Run Code Online (Sandbox Code Playgroud)
具体来说,我发现问题出在语法注释'##vso[task.setvariable variable=one]secondValue'
:我没有使用直接写入上面一行的字符串,我使用的是 bash 变量,其语法$variableName代替secondValue
问题是:
variables:
- name: one
value: "initialValue"
steps:
- task: Bash@3 …Run Code Online (Sandbox Code Playgroud) trigger:
- develop
pool:
vmImage: windows-2019
- task: MSBuild@1
inputs:
solution: '**/*.sln'
- task: DownloadBuildArtifacts@1
inputs:
buildType: 'current'
downloadType: 'single'
itemPattern: '**/*.exe'
downloadPath: '$(System.ArtifactsDirectory)'
Run Code Online (Sandbox Code Playgroud)
我在 Azure DevOps 和使用 VS Code 的 YAML 扩展中遇到此 YAML 错误。我正在尝试构建一个 Windows 服务,然后将 .exe 文件放在我可以下载的地方。
Azure 开发运营:
VS代码

错误:
隐式键需要位于一行上,隐式映射键需要后跟映射值