我使用 Azure Pipelines 来构建我的解决方案。手动构建时,用户可以决定使用哪个构建配置。现在我希望默认值(以及自动触发时的值)根据分支而不同。这是我的(非工作)方法:
name: PR-$(Build.SourceBranchName)-$(Date:yyyyMMdd)$(Rev:.r)
trigger:
- develop
- test
- master
pool:
vmImage: 'windows-latest'
parameters:
- name: BuildConfiguration
displayName: Build Configuration
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}:
default: Debug
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/test') }}:
default: Release
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
default: Release
values:
- Debug
- Release
Run Code Online (Sandbox Code Playgroud)
条件部分 ( ${{...}) 根本不起作用。(* "A template expression is not allowed in this context")
还有其他方法可以实现这一点吗?
我正在开发 azure devops 多阶段 yaml 管道。我在第一阶段设置了一个变量,然后对于下一阶段,我有一个基于该变量的条件。我还在下一阶段检索变量值。显然,在条件级别和阶段级别访问阶段间变量的语法之间存在细微差别。我无法弄清楚我需要在条件中使用的语法。我已经尝试了所有可能的变化,但似乎没有一个有效。在下面的示例中,我期望 lint 阶段能够运行,但它会被跳过。这里的条件的确切语法应该是什么?
stages:
- stage: build
displayName: build
pool:
name: Azure Pipelines
vmImage: ubuntu-latest
dependsOn: []
jobs:
- deployment: build_job
environment:
name: "test"
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
displayName: "get commitMessage variable"
name: getCommitMessage
inputs:
targetType: inline
pwsh: true
script: |
$commitMessage = "abcd_import/"
echo "setting commitMessage: $commitMessage"
echo "##vso[task.setvariable variable=commitMessage;isOutput=true]$commitMessage"
- stage: lint
displayName: lint
dependsOn:
- 'build'
condition: contains(stageDependencies.build.build_job.outputs['build_job.getCommitMessage.commitMessage'], 'import/')
pool:
name: Azure Pipelines
vmImage: ubuntu-latest
variables:
- name: BUILD_STAGE_GET_COMMIT_MESSAGE …Run Code Online (Sandbox Code Playgroud) 我想包含一个取决于变量 Agent.OS 的模板:
...
steps:
- ${{ if eq(variables['Agent.OS'], 'Linux') }}:
- template: /templates/prepare-tool.yaml
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。我在步骤列表中没有看到此步骤。我也尝试过:
- ${{ if eq(variables.AGENT_OS, 'Linux') }}:
Run Code Online (Sandbox Code Playgroud)
结果一样。
也许我错了,但是:
运行时和编译时表达式语法之间的区别主要在于可用的上下文。在编译时表达式 (${{ }}) 中,您可以访问参数和静态定义的变量。在运行时表达式 ($[ ]) 中,您可以访问更多变量,但不能访问参数。
所以,我必须使用- $[ if eq(...这个变量,它不是静态的,但它也不起作用:
意外值 '$[ if eq(variables.
我不知道如何使用这种变量。
我们一直在使用 Azure 数据工厂的“新”CICD 设置,如文档页面所述:https: //learn.microsoft.com/en-us/azure/data-factory/continuous-integration-delivery-improvements。我们使用用 YAML 编写的 Azure DevOps 管道来执行此操作。
这对我们来说一直运行得很好,直到今天早上它在验证步骤中突然开始崩溃。我们这边没有更改任何代码。我想知道版本号是否存在问题或不兼容,但我找不到任何内容。
有问题的 Azure YAML 代码是这样的:
- task: Npm@1
displayName: 'Validate ADF json'
inputs:
command: 'custom'
workingDir: $(packageJsonFolder)
customCommand: 'run build validate $(Build.Repository.LocalPath)/DataFactories/${{ parameters.folderName }} $(adfAzureResourceId)'
Run Code Online (Sandbox Code Playgroud)
完整的错误消息日志如下:
node /home/vsts/work/1/s/DataFactories/downloads/main.js validate /home/vsts/work/1/s/DataFactories/internaldataload /subscriptions/xxxxxxxxxxxxxxxx/resourceGroups/xxxxxxxxxxxxxx/providers/Microsoft.DataFactory/factories/xxxxx
/home/vsts/work/1/s/DataFactories/node_modules/@microsoft/azure-data-factory-utilities/lib/bundle.manager.js:53
throw "Execution failed with exit code: " + exitCode;
^
Execution failed with exit code: 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ build: `node node_modules/@microsoft/azure-data-factory-utilities/lib/index "validate" "/home/vsts/work/1/s/DataFactories/internaldataload" "/subscriptions/xxxxxxxxxxxxxxxx/resourceGroups/xxxxxxxxxxxxxx/providers/Microsoft.DataFactory/factories/xxxxx"`
npm ERR! Exit status …Run Code Online (Sandbox Code Playgroud) 我们正在使用 DevOps 来构建我们的 .net 4.7.2 应用程序。作为其中的一部分,我们正在运行使用 nunit 框架和测试运行器的单元测试。
它已经正常运行了大约 18 个月,但在最后一天刚刚停止工作:(
它使用标准模板来运行测试,如下所示:
- task: VSTest@2
displayName: "Running tests"
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
Run Code Online (Sandbox Code Playgroud)
但是,现在该步骤失败并显示以下日志:
NUnit 适配器 4.2.0.0:测试执行开始运行 D:\a\1\s\Configuration.Tests\bin\Release\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 中的所有测试 NUnit3TestExecutor 使用 Current Discovery 发现 0 个 NUnit 测试用例中的 0 个模式,显式运行 运行 D:\a\1\s\Configuration.Tests\bin\Release\testcentric.engine.metadata.dll 中的所有测试 NUnit3TestExecutor 使用当前发现模式发现 0 个 NUnit 测试用例中的 0 个,显式运行 运行所有测试在 D:\a\1\s\Api.Tests\bin\Release\testcentric.engine.metadata.dll 中,NUnit3TestExecutor 使用当前发现模式发现了 0 个 NUnit 测试用例中的 0 个,显式运行 在 D:\a\1 中运行所有测试\s\CommunicationTests\bin\Release\testcentric.engine.metadata.dll NUnit3TestExecutor 使用当前发现模式发现 0 个 NUnit 测试用例中的 0 个,显式运行 运行 D:\a\1\s\Domain.Tests\bin\ 中的所有测试Release\testcentric.engine.metadata.dll …
是否有一个选项可以设置自定义条件来测试上一个任务是否失败或超时?
目前,我正在使用Only when a previous task has failed当任务失败时有效的方法。如果任务超时,则不会将其视为错误并会跳过。
那么我需要一个自定义条件,例如or(failed(), timedout()). 是否可以?
语境
我们的任务遇到了这个间歇性问题npm install,我们无法找到原因,但它在下一次作业运行时得到解决,因此我们正在寻找重试功能。部分解决方案是复制npm install并使用控制选项,但它不适用于所有“失败”情况。@Levi Lu-MSFT 提供的解决方案似乎可以满足我们所有的需求(它会重试),但遗憾的是它没有解决问题,第二行重复任务也失败了。
错误示例:
20741 error stack: 'Error: EPERM: operation not permitted, unlink \'C:\\agent2\\_work\\4\\s\\node_modules\\.staging\\typescript-4440ace9\\lib\\tsc.js\'',
20741 error errno: -4048,
20741 error code: 'EPERM',
20741 error syscall: 'unlink',
20741 error path: 'C:\\agent2\\_work\\4\\s\\node_modules\\.staging\\typescript-4440ace9\\lib\\tsc.js',
20741 error parent: 's' }
20742 error The operation was rejected by your operating system.
20742 error It's possible that the file was already in use (by a …Run Code Online (Sandbox Code Playgroud) azure-devops azure-pipelines azure-pipelines-tasks azure-pipelines-yaml
我在一个分支上创建了一个 YAML 管道并从该分支对其进行了测试。我随后将其合并到 master 并删除了该分支。但是原始分支一直作为管道的默认分支出现。如何将默认值更改为“master”?
YAML 中没有任何内容来定义默认分支。这似乎是 Azure Pipelines 中的一些配置项。
我正在寻找是否可以在代理池需求中指定代理列表?在 UI azure 管道中只有两个选项等于和存在。所以,我尝试添加两个需求,但管道只需要第一个需求

yaml中同样如下,
pool:
name: AWS Pool
demands:
- Agent.Name -equals simLin02
- Agent.Name -equals ubuAgent01
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何逻辑方法可以指定 yaml 中的代理机器列表,如下所示或任何其他替代方法,我可以在其中传递代理名称列表(特定代理名称,因为并非池中的所有代理都具有所需的功能)供管道选择。
pool:
name: AWS Pool
demands:
- Agent.Name -in (simLin02, ubuAgent01)
Run Code Online (Sandbox Code Playgroud) 是否可以在 Azure devOps 管道的 HelmDeploy 任务中指定要覆盖的值?例如,类似于下面的任务(显然不能完全按原样工作):
- task: HelmDeploy@0
displayName: 'helm install'
inputs:
connectionType: 'Azure Resource Manager'
azureSubscription: '$(RM_SERVICE_CONNECTION_NAME)'
azureResourceGroup: '$(AKS_RESOURCE_GROUP)'
kubernetesCluster: '$(AKS_NAME)'
namespace: '$(AKS_NAMESPACE)'
command: 'install'
chartType: 'FilePath'
chartPath: '$(deploymentChartName)'
releaseName: test-release
overrideValues: |
value1='value_1'
value2='value_2'
Run Code Online (Sandbox Code Playgroud)
是否有任何类似于上述示例的格式可以工作?
我试图了解 Azure 构建管道中两个 nuget restore 命令之间的区别:
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
Run Code Online (Sandbox Code Playgroud)
和
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: '$(solution)'
feedsToUse: 'select'
Run Code Online (Sandbox Code Playgroud)
我试图理解,但在微软页面上,我所看到的是可以同时使用两者 - 我真的找不到任何说明差异的内容。(我也不是很明白这个feedsToUse: 'select'说法)
而且,作为第二个问题,后者和
- task: DotNetCoreCLI@2
inputs:
command: restore
projects: '**/*.csproj'
Run Code Online (Sandbox Code Playgroud)
鉴于该解决方案包含所有 csproj(并且仅包含 csproj)?
azure azure-pipelines-build-task azure-pipelines azure-pipelines-yaml