Can I create a project template in Azure DevOps - azure-devops

My company creates a lot of projects in Azure DevOps, and they all have the same structure -- same members, same permissions. Each project has different Git repositories within it, but that's the only thing (other than the name) that differs between them. It would be helpful to have a template so that everything is set up correctly each time we need a new one.
I don't see a way to do this through the web interface. I have the sense that I could probably do it with a script, but I don't know where to begin with that (including which tool to use). Where should I start?

It looks like there is now a way to do this without the Azure DevOps CLI (as long as your project that you want to template is one of the supported types (Agile, Scrum and Basic)). There is a tool available here that will step you through the process.
There is also an excellent blog post here that gives you an overview.

Yes, you can accomplish most of the configuration by script. For the beginning you might take a look at the Azure Devops CLI, which allows you to perform several actions on Azure Devops, like:
Create projects, Users and configure security
Create repositories, pipelines and set branch permissions
Create and manage work items
...

Related

Move Build and Release Pipeline from one organization to another

We have been working in one organization and now we are migrating all from one organization to another.
Can anyone suggest me How Can I Migrate my Build and Release Pipelines from one organization to another?
You can Export and Import the Pipelines as a template / JSON.
Move Build and Release Pipeline from one organization to another.
We can easily move the classic Build/Release pipelines into new Org with the Export and Import pipeline options, as Abhujit answered above.
However, we still need to modify/fix many configurations to make the newly imported pipelines work. We can't access the Private Agent Pool, Source within old Organization, so we have to do more jobs to fix them.
So if someone only needs to reuse the tasks/steps, it's easier to replicate steps to create new Build and Release pipelines instead of importing the pipelines from another org.
PS: Also, using Yaml pipelines+templates in both orgs is also a good choice for reusing tasks.
As a work-around I found this.
You can't directly import exported configuration file, You need to change lot configurations as you have change organization, which takes time. It is easier to replicate steps to create Build and Release pipelines in New Organization.

Azure DevOps: Merging two projects together

A few years ago, our team made the full transition to Azure DevOps. Before that, we had a mixture of on-prem TFS and Subversion but went to the Azure DevOps as it was easier to maintain project status between our developer and BA teams. At that time, for each project the team was working on, we just created a new "project" in Azure DevOps, but over the course of the past few years, we have found that using that method doesn't lend itself to helping us track metrics across all of those projects. We also see that maintaining multiple, separate backlogs is not ideal as we have developers spread across multiple sprints at the same time in different projects without a single place for the team leads or scrum master to fully know what their team members are working on in a single day.
Now, we've made use of queries, but those only go so far, so we've made the decision to merge our projects into a single "project". My scrum master and I have been looking at Naked Agility's merge tool, as outlined in this link: https://blog.devopsabcs.com/index.php/2019/06/12/one-project-to-rule-them-all/.
Has anyone used this tool and how well did it work for you? Also, are there any other options for merging projects together as this tool seems really complex (which the developer states is the case).
Azure DevOps: Merging two projects together
Sorry for any inconvenience.
I am afraid merging projects into a project is currently not supported in azure devops.
There is a Under Review user voice about make it possible to move a Team Project between Team Project Collections.
Merging two projects is not a simple task, it contains not only source code, build/release history, workitems and other watch outs were mainly around access and security:
External API integrations such as Web Apps, Function Apps, JIRA, Service Now
External inbound app authorisations
External outbound app authorisations such as Azure Service Principals
Variable Group authorisations to YAML Build Pipelines
Library reference updates including KeyVault
etc
This refactoring ended up being much more work than the code merge itself.
Besides, there is a Azure devops extension Migration Tools for Azure DevOps, which allow you to migrate Teams, Work Items, and Plans & Suits from one Project to another in Azure DevOps/TFS both within the same Organisation, and between Organisations. Watch the Video Overview to get you started in 30 minutes. This tool is complicated and its not always easy to discover what you need to do.
Hope this helps.

How to complete CI/CD pipelines with Azure DevOps for Azure API Management

I need help to understand better how to create complete CI/CD with Azure Devops for APim. Ok I already has explored the tools and read docs:
https://github.com/Azure/azure-api-management-devops-resource-kit
But I still have questions, my scenario:
APim dev instance with APi and operations created and others settings, as well APim prod instance created but empty.
I ran the extract tool and got the templates (not all), still need the Master (linked templates), and on this point seat my doubt, I already have 2 repos too(dev and prod).
How can I create the Master template, and how my changes from dev environment will be automatically applied to prod?
I didn't used the policyXMLBaseUrl parameters not sure what Path insert there, although seems #miaojiang inserted a folder from azure storage.
After some search and tries I deployed API's and Operations from an environment to another, but we still don't have a full automated scenario, where I make a change in a instance and that is automatically available.Is necessary to edit policies and definitions directly on the repositories or run the extract tool again.

How do I move an Azure DevOps project to a different organization?

I have got a project in an old org (from VSTS), that I want to move to my new one.
I can't see any options in Azure DevOps on migrating projects, or any information on the interwebs.
Anyone know how to do it?
If you just need to move repos, you can use the built in clone functions:
Go to the Azure Devops source repo -> Files
Click "Clone"
Choose "Generate Git Credentials"
Create the target repo in the target Azure DevOps
Choose "Import a repository"
Use the URL and credentials from Step 3
Done
This is not supported today. But this feature was planned to develop: make it possible to move a Team Project between Team Project Collections
If your Azure Devops project only tracks code versions using a single Git repo, hence no boards, user stories, tasks, pipelines, etc. then you can do the following:
Clone your project repo.
For example with Visual Studio.
You don't need to clone if you already have a local repo.
Destroy the association with the remote.
For this typically, you need to open a command line prompt in the folder that contains the .git database folder, most likely the solution folder of Visual Studio and type git remote rm origin.
Here is an example using git bash showing the content of the solution folder, including the .git database and the *.sln Visual Studio solution file:
Open the solution with Visual Studio if not already done.
It should now show that you have many commits waiting to be pushed to a remote. For illustration purpose, my toy project only have 8 commits in total.
Click the up arrow and choose your new remote, say a brand new Azure DevOps project, in the organization of your choice, then push.
You are now done cloning the project in another organization. If needed, then destroy the project in the old organization to complete the "move" operation.
There are 3 projects that I know of to achieve this.
A paid for option by Ops Hub -
OpsHub Visual Studio Migration Utility
An open source tool that requires making changes to the work item process template - Azure DevOps Migration tools
An lastly an Unofficial but still written by Microsoft tool to create Azure DevOps project templates - Azure DevOps Demo Generator & extractor tool
With the last one (the Demo Generator) you extract the project as a template, then apply it to the new organisation. As it is a tool for demo's there is no support provided and in my experience it works for simple projects but falls over on anything complex.
Expanding on others' answers, this post regards Pipelines.
Azure DevOps API
Migrating nearly all aspects of a project across organizations is doable, but it is a lot of manual work using the Azure DevOps API. The link below shows you all the end points, variables, etc. From there you'll probably want to write a Power Shell script and do a couple test runs to a dummy Organization.
https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-6.1&viewFallbackFrom=azure-devops-rest-6.0
In App options
If you avoid the API, there is no way to migrate pipelines that preserve build or release history, but you can preserve your configurations and processes by going into your Pipelines and selecting View YAML. From here you can either take this away as notes to recreate the GUI steps in your new org/project location, or actually adopt the YAML standard in your git repository.
I do not believe there is a way to migrate pipeline variables outside of the API. However, you can move the variables to Azure Key Vault and change your pipeline settings (YAML) to reference values from key vault. This is not a large amount of effort and is a nice process improvement.
Lastly, if you have any locally installed pipeline agents for releases, you will need to run the Power Shell script for your new organization on the boxes. Very simple 5m step, but right now the Agent Pools are not sharable across organization.
As #Frederic mentioned in his answer, we can actually easily do it with Visual Studio. I have done this without Visual Studio. The steps involved are below.
Add a User to Both Organization
Configure SSH Key
Update the SSH Key in Source DevOps and Clone the Repository
Check out all the Branches and Tags
Update the SSH Key in the Destination DevOps
Remove Old and Add New Origin
Push all the branches
The commands and detailed explanations can be found here.
BTW, if you need to change the entire Devops Organization tied to your personal Tenant (E.g. VS Enterprise Subscription) and move it to new Tenant, you can change the AAD and point it to the new one e.g. your EA Tenant on Azure commercial cloud.
Before you switch your organization directory, make sure the following statements are true:
You're in the Project Collection Administrator group for the
organization.
You're a member or a guest in the source Azure AD and a
member in the destination Azure AD
You have 100 or fewer users in
your source organization. Otherwise you will have to open a support ticket.
You may have to add the users back in destination org if they do not exist becuase they will loose access the moment you switch the AAD.
you could just download as a zip file and then download it to the destination repo

Reusing PowerShell Scripts in Azure DevOps

I have a PowerShell script that I want to re-use across multiple build pipelines. My question is, is there a way I can "store" or "save" my PowerShell script at the project or organization scope so that I can use it in my other build pipelines? If so, how? I can't seem to find a way to do this. It would be super handy though.
It is now possible to check out multiple repositories in one YAML pipeline. You could place your script in one repository and check it out in a pipeline of any other repository. You could then reference the script directly on the pipeline workspace.
More info here.
Depending on how big theese scripts are you can create Taskgroups that contain powershell-tasks with the script as inline-powershell. But this only works on project-scope..
Another attempt i'd try would be to create a repo containing your powershell-scripts, add this repo as submodule in the repository you are trying to build and then call the scripts from the submodule-folder. But this only works when using git-repos.
Or you could create a custom build-task that contains your script.
From what I have seen, no.
A few different options I have explored are:
If using a non-hosted agent, saving the file onto the build server. Admittedly this doesn't scale well, but it is better than copy/pasting the script all over. I was able to put these scripts into version control and deploy them via their own pipeline so that might be an solution for scaling (if necessary)
Cloning another repository that has these shared scripts during the process.
I've been asking for this feature for a bit, but it seems the Azure DevOps team has higher priorities.
How about putting the powershell in a nuget package and install that in depending projects?
I just discovered YAML templates (https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azdevops#step-re-use).
I think it may help you in this case (depending how large it is your file), you can put an inline powershell script in that template yaml, and reuse it on your main yaml.
Documentation is pretty straightforward.