I am trying to change my yaml file to add some more tasks. This is my current yaml file:
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'
I want to run one goal only if the branch that runs is master. Basically with my tests, I create a dockerfile and I want to push it to dockerhub, but I don't want that to happen every time someone opens a pull request; I want that to happen only if master is running the tests. Something like this
if branch == master
steps: *
but I don't seem to find anything in the Azure Pipelines documentation on how to do this
You can use the following condition on the task you want to condition:
eq(variables['Build.SourceBranch'], 'refs/heads/master')
https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml#examples
I do something like this as i find it easier to read later
${{ if contains(Build.SourceBranch, 'master') }}:
steps:
- task: Maven@3
inputs:
etcetera: 'etc.'
${{ else }}:
steps:
- task: Some other task
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With