我正在尝试了解用于在 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?
Run Code Online (Sandbox Code Playgroud)
我尝试了以下但似乎无法定义变量两次。
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'
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助 :-)
如果有人感兴趣,我结束了这个。
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'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1819 次 |
| 最近记录: |