I am writing inline powershell scripts in several of my release pipelines across projects. There is a good scope of reusability of these scripts. What is the best practice to put these scripts under revision control and share it across multiple projects? Is it possible to put it under a common Azure Repo project and do a git checkout from that project in my release pipeline in other projects?

- 69,186
- 6
- 100
- 141

- 24,777
- 4
- 73
- 129
-
Have you checked `task group`? Is it helpful? – Cece Dong - MSFT Feb 19 '20 at 10:09
-
@CeceDong-MSFT: I am looking at something that works cross project. E.g. some way if I can pull out common scripts from another git repo in AzDo. – Chubsdad Feb 19 '20 at 10:19
-
You can export a task group and import it to other team projects. – Cece Dong - MSFT Feb 19 '20 at 10:22
-
The problem is when I make a bug fix. Then I have to manually reimport the task group repeatedly in other projects. Too error prone.! – Chubsdad Feb 19 '20 at 13:34
-
How about using YAML build as templates as @4c74356b41 mentioned? Does your last query "Is it possible to put it under a common Azure Repo project and do a git checkout from that project in my release pipeline in other projects?" means you want to make the common project containing the script as the artifact in release pipeline? – Cece Dong - MSFT Feb 20 '20 at 13:02
-
@CeceDong-MSFT: Yes, if those scripts can be 'checked-out' from another git repo, then I could make them as a build artifact and then access it in my release pipeline. – Chubsdad Feb 21 '20 at 04:47
-
This requirement can be achieved, in release pipeline, you can use artifacts produced from continuous integration systems such as Azure Pipelines, Jenkins, or TeamCity, or use artifacts store in version control systems such as Git or TFVC. – Cece Dong - MSFT Feb 21 '20 at 09:43
-
@CeceDong-MSFT: How do I do a 'git checkout' from another git repo in release pipeline which is in a different project in Azure DevOps – Chubsdad Feb 22 '20 at 03:59
-
You can add an artifact and select `Azure Repos Git` and select the project, source and branch. – Cece Dong - MSFT Feb 24 '20 at 09:56
-
Does this solution achieve what you want? – Cece Dong - MSFT Feb 27 '20 at 03:33
2 Answers
nothing you can do for inline really, unless you are using YAML builds. For YAML builds you can use templates. Since you are asking about scripts - step templates would be a way to go in your case (most likely).

- 69,186
- 6
- 100
- 141
Update:
For your last query, making the common project containing the script as the artifact in release pipeline can be achieved, in release pipeline, you can use artifacts produced from continuous integration systems such as Azure Pipelines, Jenkins, or TeamCity, or use artifacts store in version control systems such as Git or TFVC.
You can consider using task group. A task group allows you to encapsulate a sequence of tasks, already defined in a build or a release pipeline, into a single reusable task that can be added to a build or release pipeline, just like any other task.
But task group is not able to be used across projects. You can export the task group and import to other team projects. Also, you can check the history of the task group:

- 29,631
- 1
- 24
- 39