我有2个Git存储库:一个包含应用程序的源代码,一个用于DevOps管道。
对于管道的第二阶段,我想检查触发管道的分支是否为master。 但是问题在于变量 Build.SourceBranchName 具有DevOps存储库的信息,而不是包含源代码的存储库(名为 hidden 的存储库)。
我看不到任何可用于此目的的变量。
resources:
repositories:
- repository: 'hidden'
type: git
name: 'hidden/hidden'
trigger:
- master
- develop
trigger: none
stages:
- stage: Build
displayName: Build stage
variables:
- name: BuildConfiguration
value: 'Release'
- name: ApiSolution
value: 'Company.WebApi.csproj'
jobs:
- job: BuildAPI
displayName: 'Build API'
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
- checkout: hidden
- script: dir $(Build.SourcesDirectory)
- task: Bash@3
inputs:
targetType: 'inline'
script: 'env | sort'
[...]
- stage: DeployDev
displayName: 'Deploy dev stage'
dependsOn: Build
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'master'))
jobs:
- deployment: DeployServiceApp
displayName: 'Deploy system to the dev environment job'
workspace:
clean: all
environment:
name: 'xyz'
resourceType: 'VirtualMachine'
strategy:
runOnce:
deploy:
steps:
[...]
有人对此有解决方案吗?
答案 0 :(得分:1)
请尝试通过$[ resources.repositories['other'].ref ]
获取详细信息,如显示的here
resources:
repositories:
- repository: other
type: git
name: MyProject/OtherTools
variables:
tools.ref: $[ resources.repositories['other'].ref ]
steps:
- checkout: self
- checkout: other
- bash: echo "Tools version: $TOOLS_REF"
答案 1 :(得分:0)
我们可以添加任务bash并添加脚本printenv
以打印所有env变量,然后我发现此变量BUILD_SOURCEBRANCH
,它是完整的触发器分支名称,例如refs/heads/master
>
结果:
此外,如果在环境变量中找不到所需的变量,我们可以添加Power Shell脚本并使用此API检查触发器分支。