Last active
May 13, 2024 15:54
-
-
Save chetanku/c51526d7322989ba5a62f186df261cd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Starter pipeline | |
# Start with a minimal pipeline that you can customize to build and deploy your code. | |
# Add steps that build, run tests, deploy, and more: | |
# https://aka.ms/yaml | |
trigger: | |
- master | |
pool: | |
vmImage: 'ubuntu-latest' | |
variables: | |
major: 2 | |
minor: 0 | |
stages: | |
# Versioning master branch builds | |
- stage: | |
displayName: Build_Master_Version_Number | |
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') | |
jobs: | |
- job: Build_Master_Version_Number | |
variables: | |
patch: $[counter(variables['minor'], 0)] | |
steps: | |
- bash: | | |
echo "##vso[build.updatebuildnumber]$(major).$(minor).$(patch)" | |
name: SetMasterBuildName | |
# Versioning feature branch and PR builds | |
- stage: | |
displayName: Build_Branch_Version_Number | |
condition: ne(variables['Build.SourceBranch'], 'refs/heads/master') | |
jobs: | |
- job: Build_Branch_Version_Number | |
variables: | |
prpatch: $[counter(variables['system.pullrequest.pullrequestid'], 0)] | |
brpatch: $[counter(variables['build.sourcebranchname'], 0)] | |
steps: | |
- bash: | | |
echo "##vso[build.updatebuildnumber]$(major).$(minor)-PullRequest.$(prpatch)" | |
condition: eq(variables['Build.Reason'], 'PullRequest') | |
name: SetPRBuildName | |
- bash: | | |
echo "##vso[build.updatebuildnumber]$(major).$(minor)-$(Build.SourceBranchName).$(brpatch)" | |
condition: ne(variables['Build.Reason'], 'PullRequest') | |
name: SetBranchBuildName | |
# Stage for building your application | |
- stage: Build_Steps | |
displayName: Build_Steps | |
condition: always() | |
jobs: | |
- job: Build_Steps | |
displayName: Build_Steps | |
steps: | |
- script: echo Hello, world! | |
name: 'Run_a_one_line_script' | |
- script: | | |
echo Add other tasks to build, test, and deploy your project. | |
echo See https://aka.ms/yaml | |
name: 'Run_a_multi_line_cript' | |
Thank You for this !! It is very helpful
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No worries, just wanted to point out those tips in case they could be of use to anyone else. after writing that comment, I actually had to revert some of my work trying to move down to specific tasks/jobs. I can't specify
variables:
on a task it seems, only on a job. But jobs can apparently run in parallel, so I actually hit a situation where my build ran before the script to get build number. It's possible to specify adependsOn:
, but I don't think that supports an 'or' operator to specify one job OR another. So, I had to go back to separate stages so that I had a parent stage to use as adependsOn:
My use it actually for .NET Core, but you can easily see the similarities
https://gist.github.com/nickalbrecht/51aa4a9ae2535ccc1b74110d1cf98d14