我开始使用我的YAML文件运行一些任务,并在Docker中心 IFF 分支中推送一个docker镜像等于master,否则运行一些测试并验证测试通过没有问题,我有这个YAML立即归档
trigger:
- master
jobs:
- job: runTests
pool:
vmImage: 'Ubuntu-16.04'
condition: ne(variables['Build.SourceBranch'], 'refs/heads/master'))
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'
- job: ifBranchIsMaster
pool:
vmImage: 'Ubuntu-16.04'
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master'))
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 -Ddocker.username=$(DOCKER_HUB_USER) -Ddocker.password=$(DOCKER_HUB_PASS) docker:push'
基本上,正如我们在文档右侧的here中所看到的那样,准确地说明了在什么情况下使用哪种条件以及
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master'))
在分支为master时应能正常运行,请执行以下步骤,否则跳过
但是这种情况
condition: ne(variables['Build.SourceBranch'], 'refs/heads/master'))
即使在主服务器中也可以运行,所以我读错了什么,如果分支是主服务器,我想跳过第一个测试,如果我不跳过第一个,我基本上会运行两次相同的测试
答案 0 :(得分:1)
您的缩进是错误的,应该是这样:
- job: runTests
condition: ne(variables['Build.SourceBranch'], 'refs/heads/master'))
pool:
vmImage: 'Ubuntu-16.04'