'Azure DevOps pipeline - How to tag sources when using multiple Git source repos
I have a multi-stage pipeline that is building multiple applications. I generate a common tag once per pipeline run. How do I have the pipeline update each source commit with the same tag? Using the UI tagging options causes it to only update the source repo that contains the YAML pipeline file and not any of the additional sources.
Solution 1:[1]
How do I have the pipeline update each source commit with the same tag?
You can use git commands to create same labels and add them to every repositories.
Here is the script:
- task: CmdLine@2
inputs:
script: |
git tag -a {tag} -m "{tag description}"
git push origin --tags
If you only checkout one repository in a stage, you can add this task to the stages.
If you chekout more than one repository in a stage, switch to the corresponding directory before add the tag:
- task: CmdLine@2
inputs:
script: |
cd {repository A}
git tag -a {tag} -m "{tag description}"
git push origin --tags
cd ..
cd {repository B}
git tag -a {tag} -m "{tag description}"
git push origin --tags
...
Add these tasks to all stages and you will find that the latest commits from all the repositories will be tagged.
Solution 2:[2]
Citing Brady White's response from https://developercommunity.visualstudio.com/t/missing-gui-option-create-git-tag-after-successful/1007477:
- Edit your pipeline.
- From the "..." menu just to the right of the Run button, select Triggers.
- Select the YAML tab.
- Select "Get sources"
- From there you set "Tag sources" to Never, On success, or Always.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jane Ma-MSFT |
Solution 2 | MaMazav |