Azure管道运行特定任务,如果且仅在IF中,分支在yaml中等于master

问题描述 投票:0回答:1

我正在尝试更改我的yaml文件以添加更多任务。这是我目前的yaml文件:

trigger:
  - master

pool:
  vmImage: 'Ubuntu-16.04'

steps:
  - task: Maven@3
    inputs:
      mavenPomFile: 'pom.xml'
      # according to: https://github.com/MicrosoftDocs/vsts-docs/issues/3845, 
      # maven options should go to goals instead, as mavenOptions is for jvm options
      mavenOptions: '-Xmx3072m'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.11'
      jdkArchitectureOption: 'x64'
      publishJUnitResults: true
      testResultsFiles: '**/surefire-reports/TEST-*.xml'
      goals: 'verify -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true --batch-mode --show-version'

我想只在运行的分支是master时运行一个目标。基本上我的测试,我创建了一个dockerfile,我想将它推送到dockerhub,但我不希望每次有人打开一个pull请求时都会发生这种情况。我希望只有在master运行测试时才会发生这种情况。像这样的东西

if branch == master 
steps: *

但我似乎没有在Azure管道文档中找到有关如何执行此操作的任何内容

azure-devops automated-tests azure-pipelines
1个回答
1
投票

您可以对要调整的任务使用以下条件:

eq(variables['Build.SourceBranch'], 'refs/heads/master')

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml#examples

© www.soinside.com 2019 - 2024. All rights reserved.