Azure devops 根据触发器分支设置YAML变量
我试图了解在devops中定义构建管道的yaml语法 我想根据触发构建的分支在文件中设置变量Azure devops 根据触发器分支设置YAML变量,azure-devops,Azure Devops,我试图了解在devops中定义构建管道的yaml语法 我想根据触发构建的分支在文件中设置变量 # trigger: batch: true branches: include: - master - develop - staging variables: buildConfiguration: 'Release' # Can I set this according to the branch which triggered the build?
# trigger:
batch: true
branches:
include:
- master
- develop
- staging
variables:
buildConfiguration: 'Release' # Can I set this according to the branch which triggered the build?
我尝试了以下方法,但似乎无法定义变量两次
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
variables:
condition: eq(variables['Build.SourceBranch'], 'refs/heads/develop')
buildConfiguration: 'Develop'
variables:
condition: eq(variables['Build.SourceBranch'], 'refs/heads/release')
buildConfiguration: 'Release'
感谢您的帮助:-)我可能会添加一个脚本步骤来计算这些。因此,创建某种脚本来检查$(Build.SourceBranch)的值,并像通常那样设置
buildConfiguration
的值:
echo '##vso[task.setvariable variable=buildConfiguration]something'
如果有人感兴趣的话,我就这样结束了
trigger:
batch: true
branches:
include:
- master
- develop
[truncated]
#https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#set-a-job-scoped-variable-from-a-script
- pwsh: |
If ("$(Build.SourceBranch)" -eq "refs/heads/master") {
Write-Host "##vso[task.setvariable variable=buildConfiguration;]Release"
}
If ("$(Build.SourceBranch)" -eq "refs/heads/develop") {
Write-Host "##vso[task.setvariable variable=buildConfiguration;]Debug"
}
- script: |
echo building configuration $(buildConfiguration)
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
clean: true
vsVersion: '15.0'
非常感谢。我还没见过这些。阅读时间。只需查看azure devops的
variables
文章,它提供了关于这些变量的信息。基本上你所要做的就是回显一个看起来像那样的字符串谢谢。我在设置多个YAML文件时偶然发现了这一点。。。但它似乎有点笨重,所以我将尝试使用变量。这个pwsh到底在哪里?这是完整的文件。它位于我的项目根目录中的azure-pipelines.yml中